Button group with horizontal alignment

16 visualizaciones (últimos 30 días)
Florian Berzsenyi
Florian Berzsenyi el 9 de Nov. de 2022
Editada: Goncalo el 25 de Jul. de 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)

Respuestas (1)

Nikhilesh
Nikhilesh el 18 de Nov. de 2022
Hi Florian,
Although there is no alignment settings in the panel you can always select them and arrange as per your need.
  2 comentarios
Florian Berzsenyi
Florian Berzsenyi el 18 de Nov. de 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 el 25 de Jul. de 2024
Editada: Goncalo el 25 de Jul. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Develop Apps Using App Designer en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by