David K
David K

Reputation: 1346

Change parent panel of GUIDE object

I have a Matlab GUIDE figure with nested panels. I also have control objects on top of the panels. Here's a notional example:

guide panels

In order to align all of the checkboxes, they all need to be in the same control group. I want to move the checkboxes so that their parent is the main panel rather than one of the sub-panels. The sub-panels are just there for visual grouping and don't really have a functional value.

The object browser shows the relationships, but I see no way to change it. I've tried pasting the objects I want to move outside the sub-panel and dragging them back in, but they automatically get added to the sub-panel. If I paste outside of the sub-panel I can use the arrow keys to move them back in and the parent will stay the main panel, but that gets to be tedious.

How can I change the parent panel of a GUIDE control object?

Upvotes: 1

Views: 1263

Answers (1)

il_raffa
il_raffa

Reputation: 5190

Building the GUI with guide a possible solution could be:

  • add the main uipanel
  • add all the checkbox in the main `uipanel'
  • align them (e. g. by selecting some of them and then use the Align Objects tool on the guide toolbar
  • add the secondary uipanel over some of the checkbox. It will cover the `checkbox'
  • select the secondary uipanel
  • right-click on the mouse to pop-up the context menu
  • select the Send to Back option

enter image description here

If you want to create the GUI "programmatically" you can:

  • create a figure
  • add the main panel with uipanel
  • add the checkboxes with uicontrol setting the Style property to checkbox and the position property so that they will be placed in the main panel
  • add the secondary uipanel. Also in this case the secondary uipanel will mask the checkbox
  • push the secondary panel back using the uistack function

Thsi is a possible implementation

% Create the figure
figure
% Add the Main uipanel
p1=uipanel('units','normalized','position',[.1 .1 .5 .7],'title','Main Panel')
% Add come checkboxes
cb1=uicontrol('parent',p1,'style','checkbox','units','normalized', ...
   'position',[.1 .7 .3 .1],'string','checkbox 1')
cb2=uicontrol('parent',p1,'style','checkbox','units','normalized', ...
   'position',[.1 .6 .3 .1],'string','checkbox 2')
cb3=uicontrol('parent',p1,'style','checkbox','units','normalized', ...
   'position',[.1 .5 .3 .1],'string','checkbox 3')
% Add the Secondary uipanel
p2=uipanel('parent',p1,'units','normalized','position',[.05 .4 .4 .5], ...
   'title','Secondary Panel')
% Push the secondary uipanel back
uistack(p2,'bottom')

enter image description here

Hope this helps.

Qapla'

Upvotes: 1

Related Questions