Effacer les filtres
Effacer les filtres

Radio Buttons in panel

2 vues (au cours des 30 derniers jours)
Vivek
Vivek le 8 Avr 2014
Commenté : Vivek le 9 Avr 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.

Réponse acceptée

Matt Tearle
Matt Tearle le 8 Avr 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 commentaires
Matt Tearle
Matt Tearle le 8 Avr 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 le 9 Avr 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).

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by