uistack

Reorder visual stacking of UI components

Use this function only with GUIDE, or with apps created using the figure function.

Description

example

uistack(comp) shifts the specified component up one level within the front-to-back visual stacking order of UI components. If comp is specified as a vector of UI components, each component in the vector gets shifted up by one.

example

uistack(comp,moveto) moves the UI component to another position in the stack. For example, uistack(f,'top') moves component f to the top of the current stack.

example

uistack(comp,moveto,step) specifies the number of levels to move the UI component up or down. For example, uistack(c,'up',2) moves c up two levels in the current stack.

Examples

collapse all

Create five overlapping panels with different titles and background colors.

f = figure;

a = uipanel(f,'Title','A','BackgroundColor','white');
b = uipanel(f,'Title','B','BackgroundColor','cyan');
c = uipanel(f,'Title','C','BackgroundColor','green');
d = uipanel(f,'Title','D','BackgroundColor','yellow');
e = uipanel(f,'Title','E','BackgroundColor','magenta');

a.Position = [0.35 0.50 0.30 0.35];
b.Position = [0.18 0.40 0.30 0.35];
c.Position = [0.08 0.21 0.30 0.35];
d.Position = [0.25 0.33 0.32 0.35];
e.Position = [0.30 0.27 0.30 0.35];

List the order of children in the figure.

figChildren = f.Children
figChildren = 

  5×1 Panel array:

  Panel    (E)
  Panel    (D)
  Panel    (C)
  Panel    (B)
  Panel    (A)

Reorder the panels by shifting a and c up one level in the stack, relative to their previous positions.

comp = [a c];
uistack(comp);

List the children again. Changing the stacking order of the panels also changes the order of the children in the figure.

figChildren = f.Children
figChildren = 

  5×1 Panel array:

  Panel    (E)
  Panel    (C)
  Panel    (D)
  Panel    (A)
  Panel    (B)

Create a figure that contains a tab group with five tabs.

f = figure;
tg = uitabgroup(f,'Position',[0.05 0.05 0.85 0.85]);
t1 = uitab('Title','Survey Questions');
t2 = uitab('Title','Demographic');
t3 = uitab('Title','Participant List');
t4 = uitab('Title','Raw Data');
t5 = uitab('Title','Plot');

Move the Raw Data tab to the bottom of the stack.

uistack(t4,'bottom');

Move the Survey Questions tab down two levels.

uistack(t1,'down',2);

Input Arguments

collapse all

UI component to reorder, specified as a single object or vector of objects, such as Figure, Panel, ButtonGroup, UIControl, Axes, or Tab objects. Use this argument to specify the UI components you want to reorder within the current stack.

If comp is specified as a vector of UI components, each component in the vector must share a parent and the vector must be a subset of the children of the parent container. For example, if a figure has six child UI components, the vector comp can have no more than five elements.

Location to move a UI component, specified as one of the values in the following table. Use this argument to specify the stack position you want a UI component to move to.

Move to ValueDescription
'up'Up step positions (one position by default).
'down'Down step positions (one position by default).
'top'To the top of the current stack.
'bottom'To the bottom of the current stack.

Number of levels to shift a UI component up or down in a stack, specified as a positive integer.

If you specify a step number that is greater than the number of stack levels available to move, then the UI component moves to the top or bottom of the stack. For example, if you have five stack levels and you specify a component to move down six steps, that component moves to the bottom of the stack.

Introduced before R2006a