Duplicating lines of menu/toolbar when running the APP

7 次查看(过去 30 天)
Hi all,
Recently I had an issue with my MATLAB app. Everytime I open the app, it added lines of toolbars and menu to itself. Deleting them and save will fix the issue for one time but when I open the app next time, it again automatically adds lines of toolbars and menu to itself.
Did anyone encounter similar issue? And what's your solution to it?
Thanks everyon!
Best
Zach

回答(1 个)

Anushka
Anushka 2025-2-20
I was able to reproduce this behaviour at my end. Based on my observations, you can follow the mentioned workaround to stop duplication of toolbars and menus:
  1. Open the app in MATLAB App Designer.
  2. Go to 'Code View' and inspect the 'StartupFcn' or any other initialization functions for code that adds toolbars or menus. For example, you can look for lines like:
uimenu(f, 'Text', 'New Menu');
uitoolbar(f);
In case you find such code, you can either remove it or modify it to ensure it only runs once.
3. If you want to keep the tool bar and menu creation code, implement a 'flag' to ensure it executes only once:
properties (Access = private)
MenuCreated = false;
end
function startupFcn(app)
if ~app.MenuCreated
createMenuAndToolbar(app);
app.MenuCreated = true;
end
end
By following these steps, your app should no longer add duplicate toolbars and menus each time it opens.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by