| MATLAB® | ![]() |
You can set and query graphics object properties in two ways:
The Property Inspector is an interactive tool that enables you to see and change object property values. The Property inspector is available from GUIDE, or use the inspect function at the command line.
The set and get commands enable you to set and query the values of properties
You can set default Uimenu properties on the root, figure and menu levels:
set(0,'DefaultUimenuPropertyName',PropertyValue...) set(gcf,'DefaultUimenuPropertyName',PropertyValue...) set(menu_handle,'DefaultUimenuPropertyName',PropertyValue...)
Where PropertyName is the name of the Uimenu property and PropertyValue is the value you specify as the default for that property.
For more information about changing the default value of property see Setting Default Property Values
This section lists all properties useful to uimenu objects along with valid values and instructions for their use. Curly braces { } enclose default values.
Property Name | Property Description |
|---|---|
| Accelerator | Keyboard equivalent |
| BusyAction | Callback routine interruption |
| Callback | Control action |
| Checked | Menu check indicator |
| Children | Handles of submenus |
| CreateFcn | Callback routine executed during object creation |
| DeleteFcn | Callback routine executed during object deletion |
| Enable | Enable or disable the uimenu |
| ForegroundColor | Color of text |
| HandleVisibility | Whether handle is accessible from command line and GUIs |
| Interruptible | Callback routine interruption mode |
| Label | Menu label |
| Parent | Uimenu object's parent |
| Position | Relative uimenu position |
| Separator | Separator line mode |
| Tag | User-specified object identifier |
| Type | Class of graphics object |
| UserData | User-specified data |
| Visible | Uimenu visibility |
character
Keyboard equivalent. An alphabetic character specifying the keyboard equivalent for the menu item. This allows users to select a particular menu choice by pressing the specified character in conjunction with another key, instead of selecting the menu item with the mouse. The key sequence is platform specific:
For Microsoft Windows systems, the sequence is Ctrl+Accelerator. These keys are reserved for default menu items: c, v, and x.
For UNIX systems, the sequence is Ctrl+Accelerator. These keys are reserved for default menu items: o, p, s, and w.
You can define an accelerator only for menu items that do not have children menus. Accelerators work only for menu items that directly execute a callback routine, not items that bring up other menus.
Note that the menu item does not have to be displayed (e.g., a submenu) for the accelerator key to work. However, the window focus must be in the figure when the key sequence is entered.
To remove an accelerator, set Accelerator to an empty string, ''.
cancel | {queue}
Callback routine interruption. If a callback is executing and the user triggers an event (such as a mouse click) on an object for which a callback is defined, the callback associated with the new event uses the value of BusyAction to decide whether or not to attempt to interrupt the executing callback.
If the value is cancel, the event is discarded and the second callback does not execute.
If the value is queue, and the Interruptible property of the first callback is on, the second callback is added to the event queue and executes in its turn after the first callback finishes execution.
Note If the interrupting callback is a DeleteFcn or CreateFcn callback or a figure's CloseRequest or ResizeFcn callback, it interrupts an executing callback regardless of the value of that object's Interruptible property. See theInterruptible property for information about controlling a callback's interruptibility. |
string or function handle
Menu action. A callback routine that executes whenever you select the menu. Define this routine as a string that is a valid MATLAB expression or the name of an M-file. The expression executes in the MATLAB workspace.
A menu with children (submenus) executes its callback routine before displaying the submenus. A menu without children executes its callback routine when you release the mouse button (i.e., on the button up event).
on | {off}
Menu check indicator. 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 create menus that indicate the state of a particular option. For example, suppose you have a menu item called Show axes that toggles the visibility of an axes between visible and invisible each time the user selects the menu item. If you want a check to appear next to the menu item when the axes are visible, add the following code to the callback for the Show axes menu item:
if strcmp(get(gcbo, 'Checked'),'on')
set(gcbo, 'Checked', 'off');
else
set(gcbo, 'Checked', 'on');
endThis changes the value of the Checked property of the menu item from on to off or vice versa each time a user selects the menu item.
Note that there is no formal mechanism for indicating that an unchecked menu item will become checked when selected.
Note This property is ignored for top level and parent menus. |
vector of handles
Handles of submenus. A vector containing the handles of all children of the uimenu object. The children objects of uimenus are other uimenus, which function as submenus. You can use this property to reorder the menus.
string or function handle
Callback routine executed during object creation. The specified function executes when MATLAB creates a uimenu object. MATLAB sets all property values for the uimenu before executing the CreateFcn callback so these values are available to the callback. Within the function, use gcbo to get the handle of the uimenu being created.
Setting this property on an existing uimenu object has no effect.
You can define a default CreateFcn callback for all new uimenus. This default applies unless you override it by specifying a different CreateFcn callback when you call uimenu. For example, the code
set(0,'DefaultUimenuCreateFcn','set(gcbo,...
''Visible'',''on'')')creates a default CreateFcn callback that runs whenever you create a new menu. It sets the default Visible property of a uimenu object.
To override this default and create a menu whose Visible property is set to a different value, call uimenu with code similar to
hpt = uimenu(...,'CreateFcn','set(gcbo,... ''Visible'',''off'')')
Note To override a default CreateFcn callback you must provide a new callback and not just provide different values for the specified properties. This is because the CreateFcn callback runs after the property values are set, and can override property values you have set explicitly in the uimenu call. In the example above, if instead of redefining the CreateFcn property for this uimenu, you had explicitly set Visible to off, the default CreateFcn callback would have set Visible back to the default, i.e., on. |
Do not call copyobj or textwrap (which calls copyobj) inside a CreateFcn. The act of copying the uicontrol object fires the CreateFcn repeatedly, which raises a series of error messages after exceeding the root object's RecursionLimit property.
See Function Handle Callbacks for information on how to use function handles to define a callback function.
string or function handle
Delete uimenu callback routine. A callback routine that executes when you delete the uimenu object (e.g., when you issue a delete command or cause the figure containing the uimenu to reset). MATLAB executes the routine before destroying the object's properties so these values are available to the callback routine.
The handle of the object whose DeleteFcn is being executed is accessible only through the root CallbackObject property, which is more simply queried using gcbo.
See Function Handle Callbacks for information on how to use function handles to define a callback function.
{on} | off
Enable or disable the uimenu. This property controls whether a menu item can be selected. When not enabled (set to off), the menu Label appears dimmed, indicating the user cannot select it.
ColorSpec X-Windows only
Color of menu label string. This property determines color of the text defined for the Label property. Specify a color using a three-element RGB vector or one of the MATLAB predefined names. The default text color is black. See ColorSpec for more information on specifying color.
{on} | callback | off
Control access to object's handle. This property determines when an object's handle is visible in its parent's list of children. When a handle is not visible in its parent's list of children, it is not returned by functions that obtain handles by searching the object hierarchy or querying handle properties. This includes get, findobj, gca, gcf, gco, newplot, cla, clf, and close. Neither is the handle visible in the parent figure's CurrentObject property. Handles that are hidden are still valid. If you know an object's handle, you can set and get its properties, and pass it to any function that operates on handles.
Handles are always visible when HandleVisibility is on.
Setting HandleVisibility to callback causes handles to be visible from within callback routines or functions invoked by callback routines, but not from within functions invoked from the command line. This provides a means to protect GUIs from command-line users, while allowing callback routines to have complete access to object handles.
Setting HandleVisibility to off makes handles invisible at all times. This may be necessary when a callback routine invokes a function that might potentially damage the GUI (such as evaluating a user-typed string), and so temporarily hides its own handles during the execution of that function.
You can set the root ShowHiddenHandles property to on to make all handles visible, regardless of their HandleVisibility settings. This does not affect the values of the HandleVisibility properties.
{on} | off
Callback routine interruption mode. If a callback is executing and the user triggers an event (such as a mouse click) on an object for which a callback is defined, that callback attempts to interrupt the first callback. MATLAB processes the callbacks according to these factors:
The Interruptible property of the object whose callback is executing
Whether the executing callback contains drawnow, figure, getframe, pause, or waitfor statements
The BusyAction property of the object whose callback is waiting to execute
If the Interruptible property of the object whose callback is executing is on (the default), the callback can be interrupted. Whenever the callback calls one of the drawnow, figure, getframe, pause, or waitfor functions, the function processes any events in the event queue, including the waiting callback, before performing its defined task.
If the Interruptible property of the object whose callback is executing is off, the callback cannot be interrupted (except by certain callbacks; see the note below). The BusyAction property of the object whose callback is waiting to execute determines what happens to the callback.
Note If the interrupting callback is a DeleteFcn or CreateFcn callback or a figure's CloseRequest or ResizeFcn callback, it interrupts an executing callback regardless of the value of that object's Interruptible property. The interrupting callback starts execution at the next drawnow, figure, getframe, pause, or waitfor statement. A figure's WindowButtonDownFcn callback routine, or an object's ButtonDownFcn or Callback routine are processed according to the rules described above. |
string
Menu label. A string specifying the text label on the menu item. You can specify a mnemonic for the label using the '&' character. Except as noted below, the character that follows the '&' in the string appears underlined and selects the menu item when you type Alt+ followed by that character while the menu is visible. The '&' character is not displayed. To display the '&' character in a label, use two '&' characters in the string:
'O&pen selection' yields Open selection
'Save && Go' yields Save & Go
'Save&&Go' yields Save & Go
'Save& Go' yields Save& Go (the space is not a mnemonic)
There are three reserved words: default, remove, factory (case sensitive). If you want to use one of these reserved words in the Label property, you must precede it with a backslash ('\') character. For example:
'\remove' yields remove
'\default' yields default
'\factory' yields factory
handle
Uimenu's parent. The handle of the uimenu's parent object. The parent of a uimenu object is the figure on whose menu bar it displays, or the uimenu of which it is a submenu. You can move a uimenu object to another figure by setting this property to the handle of the new parent.
scalar
Relative menu position. The value of Position indicates placement on the menu bar or within a menu. Top-level menus are placed from left to right on the menu bar according to the value of their Position property, with 1 representing the left-most position. The individual items within a given menu are placed from top to bottom according to the value of their Position property, with 1 representing the top-most position.
on | {off}
Separator line mode. Setting this property to on draws a dividing line above the menu item.
string
User-specified object label. The Tag property provides a means to identify graphics objects with a user-specified label. This is particularly useful when constructing interactive graphics programs that would otherwise need to define object handles as global variables or pass them as arguments between callback routines. You can define Tag as any string.
string (read only)
Class of graphics object. For uimenu objects, Type is always the string 'uimenu'.
matrix
User-specified data. Any matrix you want to associate with the uimenu object. MATLAB does not use this data, but you can access it using the set and get commands.
{on} | off
Uimenu visibility. By default, all uimenus are visible. When set to off, the uimenu is not visible, but still exists and you can query and set its properties.
![]() | uimenu | uint8, uint16, uint32, uint64 | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |