uimenu
Creates a menu bar for a figure.
Syntax
h = uimenu('label', menulabel)
h = uimenu('label', menulabel, property, value, ...)
h = uimenu(parent, 'label', menulabel, property, value, ...)
Inputs
- menulabel
- Text displayed for h.
- parent
- Handle of a figure.
- property, value
-
- 'createfcn'
- Function that is triggered when h is created. If value is a function handle, it must be a function that takes at least two arguments. The first argument is the handle of the uicontrol. The second argument is the event data to the uicontrol, which is ignored for createfcn. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to callback function in the additional elements. After it is executed, createfcn cannot be interrupted.
- 'deletefcn'
- Function that is triggered when h is deleted. If value is a function handle, it must be a function that takes at least two arguments. The first argument is the handle of the uicontrol. The second argument is the event data to the uicontrol, which is ignored for createfcn. If value is a string, it must represent a function handle or a function name. If value is a cell, it must contain the function name/function handle in the first cell element and parameters to pass to callback function in the additional elements. After it is executed, createfcn cannot be interrupted.
- 'enable'
- Specifies if h is enabled.
- 'tag'
- User-defined string to tag graphical control objects.
- 'userdata'
- User-defined numerical data.
Outputs
- h
- Handle of the uimenu created. The 'position' of h is in the order it is created. Once h has been created, its 'position' or 'label' on the menu bar cannot be changed.
Example
Creates a menu bar for a figure:
%Callback
function outfunc1 = func1(h,callstate)
warndlg('Some modal warning')
end
% Callback
function outfunc2 = func2(h,callstate,argument1,argument2)
disp('Menu item 2 callback')
end
f = figure;
% Test 1 Creating menu for a figure
m1 = uimenu('label', 'Menu1');
m2 = uimenu('label', 'Menu2', 'parent', f);
% Create menu items for each menu created
item1_m1 = uimenuitem('parent', m1, 'label', 'Foo1', 'callback', '@func1');
item1_m2 = uimenuitem(m2, 'label', 'A very long menu description', 'callback', {@func2, 'foo', 1});