Custom 'uimenu' concatenates each time GUI is run
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Sean de Wolski
le 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 commentaires
Kris
le 20 Nov 2014
It is quite simple like this:
existingmenus = findall( hfig, 'Type', 'uimenu' );
arrayfun(@(x) delete(x), existingmenus);
Cheers,
K
0 commentaires
Voir également
Catégories
En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!