Button group with horizontal alignment

16 vues (au cours des 30 derniers jours)
Florian Berzsenyi
Florian Berzsenyi le 9 Nov 2022
Modifié(e) : Goncalo le 25 Juil 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)

Réponses (1)

Nikhilesh
Nikhilesh le 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 commentaires
Florian Berzsenyi
Florian Berzsenyi le 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 le 25 Juil 2024
Modifié(e) : Goncalo le 25 Juil 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by