MATLAB Creating Graphical User Interfaces

(Barry) #1
Create Menus for Programmatic UIs

mh1 = uimenu(cmenu,'Label','Item 1');
mh2 = uimenu(cmenu,'Label','Item 2');
mh3 = uimenu(cmenu,'Label','Item 3');


You can specify any applicable Uimenu Properties when you define the context menu
items. See the uimenu reference page and “Add Menu Bar Menus” on page 10-66 for
information about using uimenu to create menu items. Note that context menus do not
have an Accelerator property.


NoteAfter you have created the context menu and all its items, set their
HandleVisibility properties to 'off' by executing the following statements:


cmenuhandles = findall(figurehandle,'type','uicontextmenu');
cmenuhandles.HandleVisibility = 'off';
menuitemhandles = findall(cmenuhandles,'type','uimenu');
menuitemhandles.HandleVisibility = 'off';


Associate the Context Menu with Graphics Objects


You can associate a context menu with the figure itself and with all components that
have a UIContextMenu property. This includes axes, panel, button group, all user
interface controls (uicontrols).


This code adds a panel and an axes to the figure. The panel contains a single push
button.


ph = uipanel('Parent',fh,'Units','pixels',...
'Position',[20 40 150 150]);
bh1 = uicontrol(ph,'String','Button 1',...
'Position',[20 20 60 40]);
ah = axes('Parent',fh,'Units','pixels',...
'Position',[220 40 150 150]);

Free download pdf