User`s guide
15 Examples of GUIs Created Programmatically
it the child of the main figure. This statement creates a m enu bar in the
figure and puts the File menu on it.
For each of the menu items, setting its
Parent property to the handle of the
parent menu,
hFileMenu,causesittoappearontheFile menu.
• For the main menu and each item on it, the
Label property defines the
strings that appear in the menu.
• Setting the
Separator property to on for the Close menu item causes a
separatorlinetobedrawnabovethisitem.
• For each of the m enu items, the
Callback proper ty specifies the ca llba ck
that services that item. In this example, no callback services the File menu
itself. These callbacks are defined later in the script.
See the Uicontrol Properties reference page for information about properties
of
uicontrol objects and their default values.
The Toolbar and Its Tools
These statements define the toolbar and the two buttons it contains.
hToolbar = uitoolbar(... % Too lbar for Open and Print buttons
'Parent',hMainFigure, ...
'HandleVisibility','callback');
hOpenPushtool = uipushtool(... % Open toolbar button
'Parent',hToolbar,...
'TooltipString','Open File',...
'CData',iconRead(fullfile(matlabroot,...
'toolbox\matlab\icons\opendoc.mat')),...
'HandleVisibility','callback', ...
'ClickedCallback', @h OpenMenuitemCallback);
hPrintPushtool = uipushtool(... % Print toolbar button
'Parent',hToolbar,...
'TooltipString','Print Figure',...
'CData',iconRead(fullfile(matlabroot,...
'toolbox\matlab\icons\printdoc.mat')),...
'HandleVisibility','callback', ...
'ClickedCallback', @ hPrintMenuitemCallback);
• The uit oolbar function creates the toolbar on the m ain figure.
15-12