Reorder visual stacking order of objects




uistack(h) shifts object h up one level within the visual stacking order of UI objects. You can also specify h to be a vector of UI objects. When h is a vector, the objects stack according to their order in the vector. All items in the stack must share the same parent.

uistack(h,stackopt) moves the object h to another place in the stack according to stackopt:

  • 'up' – moves h up one position in the stacking order

  • 'down' – moves h down one position in the stacking order

  • 'top' – moves h to the top of the current stack

  • 'bottom' – moves h to the bottom of the current stack

uistack(h,stackopt,step) moves object h up or down the number of levels specified by step. For example, uistack(h,'up',2) moves h up two levels in the stack.


collapse all

Change Stacking Order of Two Plots in a Figure

Create a figure containing a uipanel and a child axes. Then, plot a sine function in the axes.

f = figure;
p1 = uipanel(f,'Position',[.10 .10 .80 .80],...
            'Tag','Panel with Sine Plot');
ax1 = axes('Parent',p1,'Position',[.1 .1 .8 .8]);

theta = -3*pi:pi/64:3*pi;
y1 = sin(theta);

In the same figure, create a second uipanel with a child axes. Then, create a surface plot in this axes.

p2 = uipanel(f,'Position',[.10 .10 .80 .80],...
            'Tag','Panel with Surface Plot');
ax2 = axes('Parent',p2,'Position',[.1 .1 .8 .8]);
Z  = peaks(25);

Next, move the uipanel containing the sine function to the top.

ans = 

  2x1 Panel array:

  Panel    (Panel with Sine Plot)
  Panel    (Panel with Surface Plot)

Now, move the other uipanel to the top.

ans = 

  2x1 Panel array:

  Panel    (Panel with Surface Plot)
  Panel    (Panel with Sine Plot)

More About

expand all

Visual Stacking Order

The order of overlapping components in a UI window. Components on top of the stack appear in front of components that are lower in the stack.

Introduced before R2006a

Was this topic helpful?