Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Creating Toolbars

Creating Toolbars with GUIDE

You can add a toolbar to a GUI you create in GUIDE with the Toolbar Editor, which you open from the GUIDE Layout Editor toolbar.

You can also open the Toolbar Editor from the Tools menu.

The Toolbar Editor gives you interactive access to all the features of the uitoolbar, uipushtool, and uitoggletool functions. It only operates in the context of GUIDE; you cannot use it to modify any of the built-in MATLAB toolbars. However, you can use the Toolbar Editor to add, modify, and delete a toolbar from any GUI in GUIDE.

Currently, you can add one toolbar to your GUI in GUIDE. However, your GUI can also include the standard MATLAB figure toolbar. If you need to, you can create a toolbar that looks like a normal figure toolbar, but customize its callbacks to make tools (such as pan, zoom, and open) behave in specific ways.

If you want users to be able to dock and undock a GUI on the MATLAB desktop, it must have a toolbar or a menu bar, which can either be the standard ones or ones you create in GUIDE. In addition, the figure property DockControls must be turned on. For details, see How Menus Affect Figure Docking.

Using the Toolbar Editor

The Toolbar Editor contains three main parts:

To add a tool, drag an icon from the Tool Palette into the Toolbar Layout (which initially contains the text prompt shown above), and edit the tool's properties in the Tool Properties pane.

When you first create a GUI, no toolbar exists on it. When you open the Toolbar Editor and place the first tool, a toolbar is created and a preview of the tool you just added appears in the top part of the window. If you later open a GUI that has a toolbar, the Toolbar Editor shows the existing toolbar, although the Layout Editor does not.

Adding Tools

You can add a tool to a toolbar in three ways:

Dragging allows you to place a tool in any order on the toolbar. The other two methods place the tool to the right of the right-most tool on the Toolbar Layout. The new tool is selected (indicated by a dashed box around it) and its properties are shown in the Tool Properties pane. You can select only one tool at a time. You can cycle through the Tool Palette using the tab key or arrow keys on your computer keyboard. You must have placed at least one tool on the toolbar.

After you place tools from the Tool Palette into the Toolbar Layout area, the Toolbar Editor shows the properties of the currently selected tool, as the following illustration shows.

Predefined and Custom Tools

The Toolbar Editor provides two types of tools:

Predefined Tools.   The set of icons on the bottom of the Tool Palette represent standard MATLAB figure tools. Their behavior is built in. Predefined tools that require an axes (such as pan and zoom) do not exhibit any behavior in GUIs lacking axes. The callback(s) defining the behavior of the predefined tool are shown as %default, which calls the same function that the tool calls in standard figure toolbars and menus (to open files, save figures, change modes, etc.). You can change %default to some other callback to customize the tool; GUIDE warns you that you will modify the behavior of the tool when you change a callback field or click the View button next to it, and asks if you want to proceed or not.

Custom Tools.   The two icons at the top of the Tool Palette create pushtools and toggletools. These have no built-in behavior except for managing their appearance when clicked on and off. Consequently, you need to provide your own callback(s) when you add one to your toolbar. In order for custom tools to respond to clicks, you need to edit their callbacks to create the behaviors you desire. Do this by clicking the View button next to the callback in the Tool Properties pane, and then editing the callback in the Editor window.

Adding and Removing Separators

Separators are vertical bars that set off tools, enabling you to group them visually. You can add or remove a separator in any of three ways:

After adding a separator, that separator appears in the Toolbar Layout to the left of the tool. The separator is not a distinct object or icon; it is a property of the tool.

Moving Tools

You can reorder tools on the toolbar in two ways:

If a tool has a separator to its left, the separator moves with the tool.

Removing Tools

You can remove tools from the toolbar in three ways:

You cannot undo any of these actions.

Editing a Tool's Properties

You edit the appearance and behavior of the currently selected tool using the Tool Properties pane, which includes controls for setting the most commonly used tool properties:

See Callbacks: An Overview for details on programming the tool callbacks. You can also access these and other properties of the selected tool with the Property Inspector. To open the Property Inspector, click the More Properties button on the Tool Properties pane.

Editing Tool Icons

To edit a selected toolbar icon, click the Edit button in the Tool Properties pane, next to CData (icon) or right-click the Toolbar Layout and select Edit Icon from the context menu. The Icon Editor opens with the tool's CData loaded into it. For information about editing icons, see Using the Icon Editor.

Editing Toolbar Properties

If you click an empty part of the toolbar or click the Toolbar Properties tab, you can edit two of its properties:

The Tag property is initially set to uitoolbar1. The Visible property is set to on. When on, the Visible property causes the toolbar to be displayed on the GUI regardless of the setting of the figure's Toolbar property. If you want to toggle a custom toolbar as you can built-in ones (from the View menu), you can create a menu item, a check box, or other control to control its Visible property.

To access nearly all the properties for the toolbar in the Property Inspector, click More Properties.

Testing Your Toolbar

To try out your toolbar, click the Run button in the Layout Editor. The software asks if you want to save changes to its .fig file first.

Removing a Toolbar

You can remove a toolbar completely—destroying it—from the Toolbar Editor, leaving your GUI without a toolbar (other than the figure toolbar, which is not visible by default). The are two ways to remove a toolbar:

If you remove all the individual tools in the ways shown in Removing Tools without removing the toolbar itself, your GUI will contain an empty toolbar.

Closing the Toolbar Editor

You can close the Toolbar Editor window in two ways:

When you close the Toolbar Editor, the current state of your toolbar is saved with the GUI you are editing. You do not see the toolbar in the Layout Editor; you need to run the GUI to see or use it.

Editing Tool Icons

GUIDE includes its own Icon Editor, a GUI for creating and modifying icons such as icons on toolbars. You can access this editor only from the Toolbar Editor. This figure shows the Icon Editor loaded with a standard Save icon.

Using the Icon Editor

The Icon Editor GUI includes the following components:

To work with the Icon Editor,

  1. Open the Icon Editor for a selected tool's icon.

  2. Using the Pencil tool, color the squares in the grid:

    • Click a color cell in the palette.

    • That color appears in the Color Palette preview swatch.

    • Click in specific squares of the grid to transfer the selected color to those squares.

    • Hold down the left mouse button and drag the mouse over the grid to transfer the selected color to the squares that you touch.

    • Change a color by writing over it with another color.

  3. Using the Eraser tool, erase the color in some squares

    • Click the Eraser button on the palette.

    • Click in specific squares to erase those squares.

    • Click and drag the mouse to erase the squares that you touch.

    • Click a another drawing tool to disable the Eraser.

  4. Click OK to close the GUI and return the icon you created or click Cancel to close the GUI without modifying the selected tool's icon.

The three GUIs are shown operating together below, before saving a uipushtool icon:

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS