Button group with horizontal alignment

12 visualizzazioni (ultimi 30 giorni)
Florian Berzsenyi
Florian Berzsenyi il 9 Nov 2022
Modificato: Goncalo il 25 Lug 2024
Simple question: How can I create a button group with buttons aligned horizontally right next to, and not vertically below each other? I would like to create a group of radio button, and could not find any properties - like "Alignment" - that might do the trick.
DEFAULT BEHAVIOR DESIRED FUNCTION / BEHAVIOR
Source: MATLAB Answers (left), Google Image Link (right)

Risposte (1)

Nikhilesh
Nikhilesh il 18 Nov 2022
Hi Florian,
Although there is no alignment settings in the panel you can always select them and arrange as per your need.
  2 Commenti
Florian Berzsenyi
Florian Berzsenyi il 18 Nov 2022
this is true for the AppDesigner! I build my app programmatically.
I guess, I could manually arrange the radiobuttons with the Position property.
bg = uibuttongroup(fig,'Position',[137 113 123 85]);
% manually arrange radio button Position
rb1 = uiradiobutton(bg,'Position',[10 60 91 15]);
rb2 = uiradiobutton(bg,'Position',[10 38 91 15]);
rb3 = uiradiobutton(bg,'Position',[10 16 91 15]);
I even have to do this because I cannot fit a uigridlayout container between uibuttongroup and uiradiobutton:
bg = uibuttongroup(layFigure);
layBtnGrp = uigridlayout(bg, [3, 1], 'RowHeight', {'fit', 'fit', 'fit'}, 'ColumnWidth', {'1x'});
%example for one radiobutton, further ones are identical
rb1 = uiradiobutton(layBtnGrp, 'Text', 'Item 1'); % ERROR: 'Parent' value must be specified as a ButtonGroup object.
rb1.Layout.Row = 1;
rb1.Layout.Col = 1;
I think that I will stick with Checkboxes with radiobutton-behaviour (self-implemented) for now.
Goncalo
Goncalo il 25 Lug 2024
Modificato: Goncalo il 25 Lug 2024
I find button groups quite useless, basically it just gives you some pre-implemented functionality to manage button clicks but other than that it is super limiting. I always implement my button group so that I take advantage of gridlayouts.

Accedi per commentare.

Categorie

Scopri di più su App Building in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by