MATLAB Creating Graphical User Interfaces

(Barry) #1

10 Lay Out a Programmatic UI


Display the Standard Toolbar

Use the figure Toolbar property to display or hide the standard toolbar. Set Toolbar to
'figure' to display the standard toolbar. Set Toolbar to 'none' to hide it.

fh.Toolbar = 'figure'; % Display the standard toolbar
fh.Toolbar = 'none'; % Hide the standard toolbar

In these statements, fh is the handle of the figure.

The default ToolBar value is 'auto', which uses the MenuBar property value.

Modify the Standard Toolbar

Once you have the handle of the standard toolbar, you can add tools, delete tools, and
change the order of the tools.

Add a tool the same way you would add it to a custom toolbar. This code gets the handle
of the standard toolbar and adds a toggle tool to it.

tbh = findall(fh,'Type','uitoolbar');
tth = uitoggletool(tbh,'CData',rand(20,20,3),...
'Separator','on',...
'HandleVisibility','off');

To remove a tool from the standard toolbar, determine the handle of the tool to be
removed, and then use the delete function to remove it. The following code deletes the
toggle tool that was added to the standard toolbar above.

delete(tth)

If necessary, you can use the findall function to determine the handles of the tools on
the standard toolbar.
Free download pdf