Radio Buttons in panel

2 次查看(过去 30 天)
Vivek
Vivek 2014-4-8
评论: Vivek 2014-4-9
I created two radiobuttons on panel in GUI through script.I can select both at the same time (ie) selection is not removed when another radio bttn is selected.
Even I checked the parent of both radio button. It is same.
f1=get(findall(0,'Tag','English0'),'Parent')
f2=get(findall(0,'Tag','Metric1'),'Parent')
f1 and f2 both are same Then why a normal radio buttons functionality in single panel is not achieved?
Please suggest ideas.

采纳的回答

Matt Tearle
Matt Tearle 2014-4-8
Panels are basically just cosmetic. Use a uibuttongroup to manage the exclusivity behavior you want. Compare:
figure
pnl = uipanel('position',[0.1 0.1 0.5 0.5]);
b1 = uicontrol('parent',pnl,'units','normalized','position',[0.1 0.1 0.8 0.4],...
'style','radiobutton','string','I am a choice');
b2 = uicontrol('parent',pnl,'units','normalized','position',[0.1 0.5 0.8 0.4],...
'style','radiobutton','string','I am a choice');
versus
figure
pnl = uibuttongroup('position',[0.1 0.1 0.5 0.5]);
b1 = uicontrol('parent',pnl,'units','normalized','position',[0.1 0.1 0.8 0.4],...
'style','radiobutton','string','I am a choice');
b2 = uicontrol('parent',pnl,'units','normalized','position',[0.1 0.5 0.8 0.4],...
'style','radiobutton','string','I am a choice');
  3 个评论
Matt Tearle
Matt Tearle 2014-4-8
You don't have to specify parents to most graphical objects, but it's a recommended practice because it ensures that things end up where you expect them to. In this case, you really want the radio buttons to be inside the button group, because that manages the exclusivity.
Vivek
Vivek 2014-4-9
@ salaheddin: Imagine such a situation where you want to hide a set(say >20) of buttons and unhide a different set of buttons.
In this case, hiding/unhiding its parent is enough. So always recommended to create buttons for single requirement at panel(parent).

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by