uistack
Reorder visual stacking of UI components
Description
uistack(
shifts the specified UI
component up one level within the visual stacking order of UI components. If
comp
)comp
is a vector of UI components, uistack
shifts each component in the vector up one level.
Examples
Bring Button to Front
Create a UI figure with a button and a gauge. Because the gauge is created second, it appears in the front and covers the button.
fig = uifigure; btn = uibutton(fig,"Text","Go","Position",[148 148 25 25]); g = uigauge(fig);
Bring the button to the front by moving it to the top of the stack.
uistack(btn,"top");
Change Front-to-Back Order of Panels
Create a UI figure that contains five overlapping panels with different titles and background colors.
fig = uifigure; a = uipanel(fig,"Title","A","BackgroundColor","white","Position",[200 200 170 150]); b = uipanel(fig,"Title","B","BackgroundColor","cyan","Position",[100 170 170 150]); c = uipanel(fig,"Title","C","BackgroundColor","green","Position",[50 90 170 150]); d = uipanel(fig,"Title","D","BackgroundColor","yellow","Position",[140 140 170 150]); e = uipanel(fig,"Title","E","BackgroundColor","magenta","Position",[170 110 170 150]);
List the children in the UI figure.
fig.Children
ans = 5x1 Panel array: Panel (E) Panel (D) Panel (C) Panel (B) Panel (A)
Reorder the panels by shifting panels a
and c
up one level in the stack relative to their current 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 UI figure.
fig.Children
ans = 5x1 Panel array: Panel (E) Panel (C) Panel (D) Panel (A) Panel (B)
Reorder Nodes in Tree
Create a UI figure that contains a tree with two top-level nodes, each with two child nodes.
fig = uifigure; t = uitree(fig,"Position",[20 20 150 150]); category1 = uitreenode(t,"Text","Vegetables"); category2 = uitreenode(t,"Text","Fruits"); n1 = uitreenode(category1,"Text","Cucumber"); n2 = uitreenode(category1,"Text","Carrot"); n3 = uitreenode(category2,"Text","Apple"); n4 = uitreenode(category2,"Text","Banana");
Expand all of the nodes in the tree.
expand(t)
Move the Fruits node to the top of the stack. The node reorders relative to all other nodes that share a parent. This command moves the Fruits node and all of its child nodes above the Vegetables node.
uistack(category2,"top")
Rearrange the child nodes of the Fruits node. Move the Apple node one level down, below the Banana node.
uistack(n3,"down",1)
Reorder Tabs in Tab Group
Create a UI figure that contains a tab group with five tabs.
fig = uifigure; tg = uitabgroup(fig,"Position",[20 20 450 300]); t1 = uitab(tg,"Title","Survey Questions"); t2 = uitab(tg,"Title","Demographic"); t3 = uitab(tg,"Title","Participants"); t4 = uitab(tg,"Title","Data"); t5 = uitab(tg,"Title","Plot");
Move the Data tab to the bottom of the stack. The tab appears all the way on the right.
uistack(t4,"bottom")
Move the Survey Questions tab two levels to the right.
uistack(t1,"down",2)
Input Arguments
comp
— UI component
single object | vector of objects
UI component to reorder, specified as a single object or vector of objects, such as
Figure
, Panel
, Tab
,
Button
, or TreeNode
objects. Use this argument
to specify the UI components you want to reorder relative to other objects that share
the same parent.
If comp
is specified as a vector of UI components:
Each component in the vector must share a parent.
The vector must be a strict 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.
moveto
— Location
"up"
(default) | "down"
| "top"
| "bottom"
Location to move a UI component, specified as one of the values in this table.
Value | Description |
---|---|
"up" | Move the UI component up step levels (one level by
default). |
"down" | Move the UI component down step levels (one level by
default). |
"top" | Move the UI component to the top of its stack. |
"bottom" | Move the UI component to the bottom of its stack. |
step
— Number of levels to shift
1 (default) | positive integer
Number of levels to shift a UI component up or down in a stack, specified as a
positive integer. Use this argument only when moveto
is specified
as "up"
or "down"
.
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.
Version History
Introduced before R2006aR2023a: Change stacking order of UI components in a UI figure
You can now change the stacking order of UI components and containers in a figure
created using the uifigure
function. Previously,
uistack
supported UI components only in a figure created using the
figure
function.
R2023a: Different stacking behavior for menus, toolbars, push tools, and toggle tools
When you modify the stacking order of menus, toolbars, push tools, and toggle tools, the
behavior is different than in previous releases. For example, starting in R2023a, calling
uistack(comp,"up")
has this behavior:
Menu items parented to a figure — The menu item moves one place to the left in the menu bar. Previously, the menu item moved one place to the right.
Menu items parented to a context menu — The menu item moves one place up in the context menu. Previously, the menu item moved one place down.
Toolbars — The toolbar moves one place up within the collection of toolbars in the figure. Previously, the toolbar moved one place down.
Push tools and toggle tools — The push tool or toggle tool moves one place to the left in the toolbar. Previously, the push tool or toggle tool moved one place to the right.
If your code uses uistack
to modify the stacking order of menus,
toolbars, push tools, or toggle tools, make these updates to the code to retain the previous
behavior.
Original Code in R2022b or Earlier | Updated Code in R2023a |
---|---|
uistack(comp,"top") | uistack(comp,"bottom") |
uistack(comp,"up",step) | uistack(comp,"down",step) |
uistack(comp,"bottom") | uistack(comp,"top") |
uistack(comp,"down",step) | uistack(comp,"up",step) |
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)