| MATLAB Function Reference | ![]() |
Create menus on figure windows
Syntax
uimenu('PropertyName',PropertyValue,...) uimenu(parent,'PropertyName',PropertyValue,...) handle = uimenu('PropertyName',PropertyValue,...) handle = uimenu(parent,'PropertyName',PropertyValue,...)
Description
uimenu creates a hierarchy of menus and submenus that are displayed in the figure window's menu bar. You can also use uimenu to create menu items for context menus.
handle = uimenu(' creates a menu in the current figure's menu bar using the values of the specified properties and assigns the menu handle to PropertyName',PropertyValue,...)
handle.
handle = uimenu(parent,' creates a submenu of a parent menu or a menu item on a context menu specified by PropertyName',PropertyValue,...)
parent and assigns the menu handle to handle. If parent refers to a figure instead of another uimenu object or a Uicontextmenu, MATLAB creates a new menu on the referenced figure's menu bar.
Remarks
MATLAB adds the new menu to the existing menu bar. Each menu choice can itself be a menu that displays its submenu when selected.
uimenu accepts property name/property value pairs, as well as structures and cell arrays of properties as input arguments. The uimenu Callback property defines the action taken when you activate the menu item. uimenu optionally returns the handle to the created uimenu object.
Uimenus only appear in figures whose WindowStyle is normal. If a figure containing uimenu children is changed to WindowStyle modal, the uimenu children still exist and are contained in the Children list of the figure, but are not displayed until the WindowStyle is changed to normal.
The value of the figure MenuBar property affects the location of the uimenu on the figure menu bar. When MenuBar is figure, a set of built-in menus precedes the uimenus on the menu bar (MATLAB controls the built-in menus and their handles are not available to the user). When MenuBar is none, uimenus are the only items on the menu bar (that is, the built-in menus do not appear).
You can set and query property values after creating the menu using set and get.
Properties
This table lists all properties useful to uimenu objects, grouping them by function. Each property name acts as a link to a description of the property.
| Property Name |
Property Description |
Property Value |
| Controlling Style and Appearance | ||
Checked |
Menu check indicator |
Value: on, offDefault: off |
ForegroundColor |
Color of text |
Value: ColorSpecDefault: [0 0 0] |
Label |
Menu label |
Value: string |
SelectionHighlight |
Object highlighted when selected |
Value: on, offDefault: on |
Separator |
Separator line mode |
Value: on, offDefault: off |
Visible |
Uimenu visibility |
Value: on, offDefault: on |
| General Information About the Object | ||
Accelerator |
Keyboard equivalent |
Value: character |
Children |
Handles of submenus |
Value: vector of handles |
Enable |
Enable or disable the uimenu |
Value: on, offDefault: on |
Parent |
Uimenu object's parent |
Value: handle |
Tag |
User-specified object identifier |
Value: string |
Type |
Class of graphics object |
Value: string (read-only) Default: uimenu |
UserData |
User-specified data |
Value: matrix |
| Controlling the Object Position | ||
Position |
Relative uimenu position |
Value: scalar Default: [1] |
| Controlling Callback Routine Execution | ||
BusyAction |
Callback routine interruption |
Value: cancel, queueDefault: queue |
ButtonDownFcn |
Button press callback routine |
Value: string |
Callback |
Control action |
Value: string |
CreateFcn |
Callback routine executed during object creation |
Value: string |
DeleteFcn |
Callback routine executed during object deletion |
Value: string |
Interruptible |
Callback routine interruption mode |
Value: on, offDefault: on |
| Controlling Access to Objects | ||
HandleVisibility |
Whether handle is accessible from command line and GUIs |
Value: on, callback, offDefault: on |
HitTest |
Whether selectable by mouse click |
Value: on, offDefault: on |
Examples
This example creates a menu labeled Workspace whose choices allow users to create a new figure window, save workspace variables, and exit out of MATLAB. In addition, it defines an accelerator key for the Quit option.
f = uimenu('Label','Workspace'); uimenu(f,'Label','New Figure','Callback','figure'); uimenu(f,'Label','Save','Callback','save'); uimenu(f,'Label','Quit','Callback','exit',... 'Separator','on','Accelerator','Q');
Object Hierarchy
See Also
uicontrol, uicontextmenu, gcbo, set, get, figure
| uiimport | Uimenu Properties | ![]() |