MATLAB Answers

Matt J

Hide and disable uicontrols in groups

Asked by Matt J
on 18 Apr 2013

I'm designing GUIs where, sometimes, I want whole groups of uicontrols to be hidden from and inaccessible to the user. The tedious way to do this would be to set the Enable and Visibility properties to 'off' for each button individually. However, I was hoping for some way to designate them as a group and hide them using a single property set.

My first thought was to put them all on a uipanel and control them all through that. This works fine for controlling Visibility. Setting the panel's visibility property off hides everything. However, there doesn't seem to be a corresponding Enable property in a uipanel that can be used to deactivate all the uicontrols residing within it. I tried the HitTest property. That didn't work.

Any recommendations for how best to do this?



No products are associated with this question.

2 Answers

Answer by Image Analyst
on 18 Apr 2013
 Accepted answer

I think you can pass in an array of handles to set()

% Get all the handles to everything we want to set in a single array.
handleArray = [handles.editText, handles.pushbutton, handles.listbox];
% Set them all disabled.
set(handlesArray, 'Enable', 'off');


That would be nice. It's like that for the 'Visible' property, where if you set the visible property to off or on, it makes the panel and all it's contents visible or invisible.

set( findall(handles.your_uipanel, '-property', 'Enable'), 'Enable', 'off')

Nice one, Walter! If you convert it to an Answer, I'll +1 it.

Answer by Sean de Wolski
on 29 Apr 2013

If you are writing the GUI programatically, I suggest writing your own uipanel class. This class would wrap around a regular panel and farm almost all commands to this uipanel. You could then add the properties you want to this class and have it internally disable all of its children. I.e. setting the 'Enable' property of this class will disable all of the children of the uipanel.

You'll end up doing essentially the same thing IA or Walter described but hide it in this class. It's also very reusable for future GUIs.

I did something similar with my pointyColorbar class and a few other classes I've written when I wanted to add a property to a predefined HG object.


You would have to add them programatically in the OpeningFcn or OutputFcn.

This actually shouldn't be too difficult, here is the general workflow I imagine:

  • Define your class
  • Build the GUI in GUIDE and add the uipanel which you want to "supe-up"
  • In the OutputFcn call the constructor to your extended uipanel class (pass in the uipanel's handle) and add the extended uipanel handle to handles. (You could at the same time remove the uipanel's handle from handles to safeguard against accidentally using it. Though this shouldn't be a worry unless it is deleted without the object's knowledge (The object could listen for this event))
  • Everywhere you want to use the extended functionality, do the operation on the handle to your object.

That sounds like it would work. I guess you could flag the uipanels in GUIDE that you want to supe-up using its UserData.

If get() and set() in your class extended uipanel class properly overloaded getting and setting the regular properties to the uipanel (e.g: BorderType or FontUnits), then replacing the handle in the handles struct with that of your object should be okay.


handles.uipanel1 = hExtendedPanel(handles.uipanel1);

Now nothing would need to be stored in UserData, nothing would seemingly change anywhere else, but you would have an extended uipanel!

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!