Filter löschen
Filter löschen

Button group with horizontal alignment

20 Ansichten (letzte 30 Tage)
Florian Berzsenyi
Florian Berzsenyi am 9 Nov. 2022
Bearbeitet: Goncalo am 25 Jul. 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)

Antworten (1)

Nikhilesh
Nikhilesh am 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 Kommentare
Florian Berzsenyi
Florian Berzsenyi am 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 am 25 Jul. 2024
Bearbeitet: Goncalo am 25 Jul. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by