MenuBar

版本 1.8.0.0 (13.2 KB) 作者: Dirk-Jan Kroon
Create Menu Bar (s) on any location in a figure window
2.1K 次下载
更新时间 2011/1/12

查看许可证

编者注: This file was selected as MATLAB Central Pick of the Week

This function MenuBar, allows the user to create menu's anywhere in a figure
it replaces UIcontextmenu of UIpanels by real menu bars.

menubar(figure_handle) or menubar

Mouse hover, and window-resize updates can be enabled by

menubar('start',figure_handle) or menubar('start')

Or alternatively by:

set(figure_handle,'ResizeFcn','menubar(''ResizeFcn'',gcf)');
set(figure_handle,'WindowButtonMotionFcn','menubar(''MotionFcn'',gcf)');

Example,

%Creat figure with uipanel
figure,
uipanel1 = uipanel('Units','Pixels','Position',[10 200 400 200]);

%Attach a contextmenu (right-mouse button menu)
menu_panel1=uicontextmenu;
set(uipanel1,'UIContextMenu',menu_panel1);

%Add menu-items to the context menu
hchild=uimenu(menu_panel1, 'Label', 'Random Pixels');
uimenu(hchild, 'Label', 'Red','Callback','disp(''Red callback'')');
uimenu(hchild, 'Label', 'Blue','Callback','disp(''Blue callback'')');

%Make form the context menu a real menubar
menubar

%Add some other menu-buttons
hchild=uimenu(menu_panel1, 'Label', 'Clear','Callback','disp(''Clear'')');
hchild=uimenu(menu_panel1, 'Label', 'Help');
uimenu(hchild, 'Label', 'Info','Callback','disp(''Info callback'')');

%Update the menubar
menubar

%Enable the mouse over and resize effects
menubar('start');

引用格式

Dirk-Jan Kroon (2024). MenuBar (https://www.mathworks.com/matlabcentral/fileexchange/29760-menubar), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2010b
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.8.0.0

Now also works with regular callback functions.

1.7.0.0

Instead of using a timer for every uipanel it uses one timer for the whole figure.

1.4.0.0

Solved bug: "Matlab is slow after doing many menubar updates"

1.3.0.0

Menubar width is now equal to uipanel width. Uipanel no longer set to invisible.

1.2.0.0

Fixed bug: in subsub-menu

1.1.0.0

Figure Resize Detection.

1.0.0.0