uicontextmenu - Create context menu

Syntax

handle = uicontextmenu('PropertyName',PropertyValue,...)

Description

handle = uicontextmenu('PropertyName',PropertyValue,...) creates a context menu, which is a menu that appears when the user right-clicks on a graphics object. See the Uicontextmenu Properties reference page for more information.

You create context menu items using the uimenu function. Menu items appear in the order the uimenu statements appear. You associate a context menu with an object using the UIContextMenu property for the object and specifying the context menu's handle as the property value.

Example

These statements define a context menu associated with a line. When the user right clicks or presses Alt+click anywhere on the line, the menu appears. Menu items enable the user to change the line style.

% Define the context menu
cmenu = uicontextmenu;
% Define the line and associate it with the context menu
hline = plot(1:10, 'UIContextMenu', cmenu);
% Define callbacks for context menu items
cb1 = ['set(gco, ''LineStyle'', ''--'')'];
cb2 = ['set(gco, ''LineStyle'', '':'')'];
cb3 = ['set(gco, ''LineStyle'', ''-'')'];
% Define the context menu items
item1 = uimenu(cmenu, 'Label', 'dashed', 'Callback', cb1);
item2 = uimenu(cmenu, 'Label', 'dotted', 'Callback', cb2);
item3 = uimenu(cmenu, 'Label', 'solid', 'Callback', cb3);

When the user right clicks or presses Alt+click on the line, the context menu appears, as shown in this figure:

See Also

uibuttongroup, uicontrol, uimenu, uipanel

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS