Radio Buttons in panel

4 views (last 30 days)
Vivek
Vivek on 8 Apr 2014
Commented: Vivek on 9 Apr 2014
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.

Accepted Answer

Matt Tearle
Matt Tearle on 8 Apr 2014
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 Comments
Matt Tearle
Matt Tearle on 8 Apr 2014
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 on 9 Apr 2014
@ 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).

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!