MATLAB Creating Graphical User Interfaces

(Barry) #1
Create Menus for Programmatic UIs

Add Context Menus to a Programmatic UI


Context menus appear when the user right-clicks on a figure or UI component. Follow
these steps to add a context menu to your UI:

1 Create the context menu object using the uicontextmenu function.
2 Add menu items to the context menu using the uimenu function.
3 Associate the context menu with a graphics object using the object's UIContextMenu
property.

Subsequent topics describe commonly used context menu properties and explain each of
these steps:


  • “Commonly Used Properties” on page 10- 73

  • “Create the Context Menu Object” on page 10- 74

  • “Add Menu Items to the Context Menu” on page 10- 74

  • “Associate the Context Menu with Graphics Objects” on page 10- 75

  • “Force Display of the Context Menu” on page 10- 77


Commonly Used Properties

The most commonly used properties needed to describe a context menu object are shown
in the following table. These properties apply only to the menu object and not to the
individual menu items.

Property Values Description


HandleVisibility on, off. Default is on. Determines if an object's handle is visible in
its parent's list of children. For menus, set
HandleVisibility to off to protect menus
from operations not intended for them.


Parent Figure handle Handle of the context menu's parent figure.


Position 2-element vector:
[distance from left,
distance from bottom].
Default is [0 0].


Distances from the bottom left corner of the
parent figure to the top left corner of the
context menu. This property is used only when
you programmatically set the context menu
Visible property to on.
Free download pdf