Button group with horizontal alignment

20 次查看(过去 30 天)
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)

回答(1 个)

Nikhilesh
Nikhilesh 2022-11-18
Hi Florian,
Although there is no alignment settings in the panel you can always select them and arrange as per your need.
  2 个评论
Florian Berzsenyi
Florian Berzsenyi 2022-11-18
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 2024-7-25
编辑:Goncalo 2024-7-25
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by