Radio Buttons in panel

조회 수: 1 (최근 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