14 Examples of UIs Created Programmatically
- For a push button, the String property defines the label on the button. Here it is
defined as the string, 'Update'. - Setting the Callback property to @hUpdateButtonCallback specifies the function,
hUpdateButtonCallback to be the function that executes when the user presses the
push button. This callback function is a nested function in the same file.
The File Menu and Its Menu Items
These statements define the File menu and the three items it contains.
hFileMenu = uimenu(... % File menu
'Parent',hMainFigure,...
'HandleVisibility','callback', ...
'Label','File');
hOpenMenuitem = uimenu(... % Open menu item
'Parent',hFileMenu,...
'Label','Open',...
'HandleVisibility','callback', ...
'Callback', @hOpenMenuitemCallback);
hPrintMenuitem = uimenu(... % Print menu item
'Parent',hFileMenu,...
'Label','Print',...
'HandleVisibility','callback', ...
'Callback', @hPrintMenuitemCallback);
hCloseMenuitem = uimenu(... % Close menu item
'Parent',hFileMenu,...
'Label','Close',...
'Separator','on',...
'HandleVisibility','callback', ...
'Callback', @hCloseMenuitemCallback);
- The uimenu function creates both the main menu, File, and the menu items under
it. For the main menu and each of its items, set the Parent property to the handle of
the desired parent to create the menu hierarchy you want. Here, setting the Parent
property of the File menu to hMainFigure makes it the child of the main figure. This
statement creates a menu 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, causes it to appear on the File menu.
- The Label property defines the text label for each menu item.
- Setting the Separator property to 'on' for creates a separator line above a menu
item.