Creating Graphical User Interfaces Previous page   Next Page

Defining Context Menus

A context menu is displayed when a user right-clicks on the object for which the menu is defined. The Menu Editor enables you to define context menus and associate them with objects in the layout.

See Defining Menus for the Menu Bar for information about defining menus in general.

Creating the Parent Menu

All items in a context menu are children of a menu that is not displayed on the figure menu bar. To define the parent menu, select New Context Menu from the Menu Editor's toolbar.

menu editor with cursor pointing to new context menu

Select the menu and specify the Tag to identify the context menu (axes_context_menu in this example).

Adding Items to the Context Menu

Create the items that will appear in the context menu using New Menu Item on the Menu Editor's toolbar.

menu editor with cursor pointing to new menu item

When you select the menu item, the Menu Editor displays fields for you to enter the Label and Tag properties of the menu item.

adding blue and red background color to the axes context menu

You can also

Associating the Context Menu with an Object

In the Layout Editor, select the object for which you are defining the context menu. Use the Property Inspector to set this object's UIContextMenu property to the name of the desired context menu.

property inspector menu

In the GUI M-file, complete the callback subfunction for each item in the context menu. Each callback executes when a user selects the associated context menu item. See Menu Callbacks for information on defining the syntax.


Previous page  Menu Callbacks Setting the Tab Order Next page

© 1994-2005 The MathWorks, Inc.