Main Content

uitoolbar

Create toolbar in figure

Description

tb = uitoolbar creates a toolbar in the current figure and returns the Toolbar object. If a figure created with the figure function does not exist, then MATLAB® creates one to serve as the parent.

tb = uitoolbar(parent) creates a toolbar in the specified parent figure.

example

tb = uitoolbar(___,Name,Value) creates a toolbar with property values specified using one or more name-value arguments. Specify name-value arguments with either of the previous syntaxes.

Examples

collapse all

Create a UI figure by calling the uifigure function. Add a toolbar to the figure.

f = uifigure;
tb = uitoolbar(f);

Figure with an empty toolbar

Create a push tool in the toolbar, and specify the toolbar icon as the image pepper.png.

pt = uipushtool(tb,Icon="peppers.png");

Figure with a toolbar containing a push tool with an image of peppers

Change the left-to-right order of tools in a toolbar. In this case, reverse the order of a push tool and toggle tool that are in a UI figure toolbar.

Create a UI figure. Add a toolbar to it. Then, add a push tool and toggle tool to the toolbar.

fig = uifigure;
tb = uitoolbar(fig);
pt = uipushtool(tb);
tt = uitoggletool(tb);

Set the Icon property of the push tool to the image file peppers.png.

pt.Icon = "peppers.png";

Create a blue truecolor image array. Set the Icon property of the toggle tool to this array to display a blue square icon.

ttImage = zeros(16,16,3);
ttImage(:,:,3) = ones(16);
tt.Icon = ttImage;

Figure window with a toolbar with two tools. The push tool with an icon of peppers is on the left, and the toggle too with an icon of a blue square is on the right

Query the Children property of the toolbar. The order of the children returned in this array reflects the right-to-left order of the tools displayed in the toolbar. The toggle tool is the right-most tool and appears at the top of the list (the first element of the array).

oldToolOrder = tb.Children
oldToolOrder = 

  2×1 graphics array:

  ToggleTool
  PushTool

Reverse the order of the tools by calling the flipud function to flip the order of the elements in the array returned by tb.Children. Set the Children property value to this new tool order. The push tool now appears to the right of the toggle tool in the toolbar.

newToolOrder = flipud(oldToolOrder);
tb.Children = newToolOrder;

Blue toggle tool appears to the left of the push tool in the toolbar

Input Arguments

collapse all

Parent figure, specified as a Figure object. If a parent figure is not specified, then MATLAB calls the figure function to create one that serves as the parent.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Visible','off' sets the visibility of the toolbar to 'off'.

Note

The properties listed here are only a subset. For a complete list, see Toolbar.

State of visibility, specified as 'on' or 'off', or as numeric or logical 1 (true) or 0 (false). A value of 'on' is equivalent to true, and 'off' is equivalent to false. Thus, you can use the value of this property as a logical value. The value is stored as an on/off logical value of type matlab.lang.OnOffSwitchState.

  • 'on' — Display the object.

  • 'off' — Hide the object without deleting it. You still can access the properties of an invisible UI component.

To make your app start faster, set the Visible property to 'off' for all UI components that do not need to appear at startup.

Toolbar children, returned as an empty GraphicsPlaceholder or a 1-D array of component objects. The children of Toolbar objects are PushTool and ToggleTool objects.

You cannot add or remove children using the Children property. Use this property to view the list of children or to reorder the children. The order of the children in this array reflects the right-to-left order of the tools displayed in the toolbar. Meaning that the right-most tool is at the top of the list and the left-most tool is at the bottom of the list. For example, this tool order returned by the Children property indicates that the push tool appears to the left of the toggle tool in the toolbar.

toolOrder = tb.Children
toolOrder = 

  2×1 graphics array:

  ToggleTool
  PushTool

To add a child to this list, set the Parent property of the child component to the uitoolbar object.

Objects with the HandleVisibility property set to 'off' are not listed in the Children property.

Tips

  • Toolbars can contain push tools or toggle tools. Push tools behave like push buttons. When you click them, they appear to depress until you release the mouse button. Toggle tools have two states: 'off' or 'on'. The state of the button changes every time you click it.

  • Toolbar objects (and their child PushTool and ToggleTool objects) do not appear in figures whose WindowStyle property is set to 'modal'. If a figure containing a toolbar child has its WindowStyle changed to 'modal', the toolbar child still exists in the Children property of the figure. However, the toolbar does not appear while WindowStyle is set to 'modal'.

Version History

Introduced before R2006a

expand all

See Also

Functions

Properties