10 Lay Out a Programmatic UI
Property Values Description
Visible off, on. Default is
off
- Indicates whether the context menu is
currently displayed. While the context menu
is displayed, the property value is on; when
the context menu is not displayed, its value is
off. - Setting the value to on forces the posting of
the context menu. Setting to off forces the
context menu to be removed. The Position
property determines the location where the
context menu is displayed.
For a complete list of properties and for more information about the properties listed in
the table, see Uicontextmenu Properties.
Create the Context Menu Object
Use the uicontextmenu function to create a context menu object. The syntax is
handle = uicontextmenu('PropertyName',PropertyValue,...)
The parent of a context menu must always be a figure. Use the Parent property to
specify the parent of a uicontextmenu. If you do not specify the Parent property, the
parent is the current figure as specified by the root CurrentFigure property.
The following code creates a figure and a context menu whose parent is the figure. At this
point, the figure is visible, but not the menu.
fh = figure('Position',[300 300 400 225]);
cmenu = uicontextmenu('Parent',fh,'Position',[10 215]);
Note“Force Display of the Context Menu” on page 10-77 explains the use of the
Position property.
Add Menu Items to the Context Menu
Use the uimenu function to add items to the context menu. The items appear on the
menu in the order in which you add them. The following code adds three items to the
context menu created above.