Azzera filtri
Azzera filtri

Custom 'uimenu' concatenates each time GUI is run

1 visualizzazione (ultimi 30 giorni)
TJ
TJ il 29 Gen 2013
Risposto: Kris il 20 Nov 2014
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');

Risposte (2)

Sean de Wolski
Sean de Wolski il 29 Gen 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');

Kris
Kris il 20 Nov 2014
It is quite simple like this:
existingmenus = findall( hfig, 'Type', 'uimenu' );
arrayfun(@(x) delete(x), existingmenus);
Cheers,
K

Categorie

Scopri di più su Printing and Saving in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by