Control appearance and behavior of menu
Menus display drop-down lists of options at the top of an app window. Call the
uimenu function to create a menu or
add a submenu to an existing menu. Properties control the appearance and behavior of a
menu. Use dot notation to refer to a specific object and property.
uf = uifigure; m = uimenu(uf); m.Text = 'Open Selection';
The properties listed here are valid for menus in App Designer, or in apps created
uifigure function. For menus used in GUIDE, or in apps
created with the
figure function, see Menu Properties.
Text— Menu label
Menu label, specified as a character vector or string scalar. This property specifies the label that appears on the menu or menu item.
Avoid using these case-sensitive reserved words: "default", "remove", and
"factory". If you must use a reserved word, then specify a backslash
character before the word. For instance, specify "default" as
You can specify a mnemonic keyboard shortcut
mnemonic) by using the
ampersand (&) character in the text for the label. The character that
follows the ampersand appears underlined in the menu when
Alt is pressed. You can select the menu item by holding
down the Alt key and typing the character shown.
To use mnemonics, you must specify a mnemonic for all menus and menu items that you define in the app. If you define mnemonics only for some menus or menu items, pressing the Alt key does not have any effect.
The table shows some examples:
|Text Value||Menu Label with Mnemonic Hints|
Accelerator— Keyboard shortcut
Keyboard shortcut, specified as a character. Use this property to define a keyboard shortcut for selecting a menu item.
mitem.Accelerator = 'H'
Specifying an accelerator value enables users to select the menu item by pressing a character and another key, instead of using the mouse. The key sequence is platform specific.
Things to keep in mind when using accelerators:
The app window must be in focus when entering the accelerator key sequence.
Accelerators cannot be used on top-level menus.
Accelerators only work when the menu item meets all these criteria.
It does not contain any submenu items.
It executes a callback function.
It has the
Visible property set
Separator— Separator line mode
Separator line mode, specified as
'on'. Setting this property to
'on' draws a dividing line above the menu item.
Separator property is ignored when the
menu item is a top-level menu item.
Checked— Menu check indicator
Menu check indicator, specified as
'on'. Setting this property to
'on' places a check mark next to the corresponding
menu item. Setting it to
'off' removes the check mark.
You can use this feature to show the state of menu items that enable or
disable functionality in your application.
Checked property is ignored when the menu
A top-level menu item
A menu item that contains one or more child menu items
ForegroundColor— Menu label color
[0 0 0](default) | RGB triplet | hexadecimal color code |
Menu label color, specified as an RGB triplet, a hexadecimal color code or one of the color options listed in the table.
RGB triplets and hexadecimal color codes are useful for specifying custom colors.
An RGB triplet is a three-element row vector whose elements specify the
intensities of the red, green, and blue components of the color. The intensities
must be in the range
[0,1]; for example,
A hexadecimal color code is a character vector or a string scalar that starts
with a hash symbol (
#) followed by three or six hexadecimal
digits, which can range from
values are not case sensitive. Thus, the color codes
Alternatively, you can specify some common colors by name. This table lists the named color options, the equivalent RGB triplets, and hexadecimal color codes.
|Color Name||Short Name||RGB Triplet||Hexadecimal Color Code||Appearance|
Here are the RGB triplets and hexadecimal color codes for the default colors MATLAB® uses in many types of plots.
|RGB Triplet||Hexadecimal Color Code||Appearance|
Visible— Menu visibility
Menu visibility, specified as
'off'. When the
is set to
'off', the menu is not visible, but you can
query and set its properties.
Enable— Operational state of menu
Operational state of menu, specified as
'off'. This property controls whether the user can
select a menu item. When the value is
'off', the menu
label appears dimmed, indicating that the user cannot select it.
''(default) | character vector | cell array of character vectors | string array | 1-D categorical array
Tooltip, specified as a character vector, cell array of character vectors, string array, or 1-D categorical array. Use this property to display a message when the user hovers the pointer over the component at run time. The tooltip displays even when the component is disabled. To display multiple lines of text, specify a cell array of character vectors or a string array. Each element in the array becomes a separate line of text. If you specify this property as a categorical array, MATLAB uses the values in the array, not the full set of categories.
MenuSelectedFcn— Menu selected callback
''(default) | function handle | cell array | character vector
Menu selected callback, specified as one of these values:
A function handle.
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
The callback responds depending on the location of the menu item and the type of interaction:
Left-clicking a menu expands that menu and triggers its callback.
While any menu is expanded, hovering any other parent menu (or top-level menu) expands that menu and triggers its callback.
Do not use a callback to dynamically change menu items. Deleting,
adding, and replacing menu items in a callback can result in a blank
menu. Instead, use the
Visible property to hide or
show menu items. You can also enable and disable menu items by setting
Enable property. To fully repopulate menu
items, delete and create them outside the callback.
For more information about writing callbacks, see Write Callbacks in App Designer.
Parent— Parent object
Parent object, specified as a
created using the
uifigure function, or a
Menu object. You can move a menu item to a different
window, or move it under a different menu by setting this property.
Children— Menu children
GraphicsPlaceholderarray (default) | 1-D array of
Menu children, returned as an empty
or a 1-D array of
You cannot add or remove child components using the
Children property. Use this property to view the list
of children or to reorder the child menu items.
To add a child menu to this list, set the
property of another
Menu object to this
Type— Type of graphics object
This property is read-only.
Type of graphics object, returned as