Custom 'uimenu' concatenates each time GUI is run
5 views (last 30 days)
Show older comments
I've just started working on writing GUIs without using GUIDE. Each time I run my GUI function that has a custom dropdown uimenu (i.e.[File Edit Search], the uimenu keeps concatenating onto the figure unless I close the figure window out completely.
For instance, after running the function twice, the menu bar reads [File Edit Search File Edit Search].
I have tried setting the 'menubar' property to 'none', and I've tried clearing the uimenu handle at the beginning of the function. Nothing seems to work.
Here is some example code taken from the mathworks website. If you drop this into the editor and run it a few times without closing the figure, you'll end up with a figure with multiple finds in the menu bar. Thanks in advance.
f = figure(22);
set(f, 'MenuBar','None');
mh = uimenu(f,'Label','Find');
frh = uimenu(mh,'Label','Find and Replace ',...
'Callback','goto',...
'Accelerator', 'Q');
frh = uimenu(mh,'Label','Variable','Separator', 'on' );
uimenu(frh,'Label','Name', ...
'Callback','variable');
0 Comments
Answers (2)
Sean de Wolski
on 29 Jan 2013
Every time you call:
mh = uimenu(f,'Label','Find');
It adds another menu. If you instead want to overwrite or delete the existing menu either delete() it or set() its properties to be something else.
f = figure(22);
set(f, 'MenuBar','None');
if exist('mh','var') %if it's there, delete it.
delete(mh);
end
mh = uimenu(f,'Label','Find');
frh = uimenu(mh,'Label','Find and Replace ',...
'Callback','goto',...
'Accelerator', 'Q');
frh = uimenu(mh,'Label','Variable','Separator', 'on' );
uimenu(frh,'Label','Name', ...
'Callback','variable');
0 Comments
Kris
on 20 Nov 2014
It is quite simple like this:
existingmenus = findall( hfig, 'Type', 'uimenu' );
arrayfun(@(x) delete(x), existingmenus);
Cheers,
K
0 Comments
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!