View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

5.0 | 3 ratings Rate this file 7 Downloads (last 30 days) File Size: 13.2 KB File ID: #29760 Version: 1.8
image thumbnail



Dirk-Jan Kroon (view profile)


17 Dec 2010 (Updated )

Create Menu Bar (s) on any location in a figure window

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

 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:



   %Creat figure with uipanel
  uipanel1 = uipanel('Units','Pixels','Position',[10 200 400 200]);
   %Attach a contextmenu (right-mouse button menu)

   %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
   %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

   %Enable the mouse over and resize effects

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
03 Nov 2012 per isakson

MenuBar adds both to the appearance and usability of my guis. Furthermore, I learn from the code.

I replaced imshow by image (R2012a) and to suppress tickmarks and labels I added the following line directly after "... image( barimage, ..."

set( data.menuitems(i).Handle, 'Visible', 'off' )

The behavior of MenuBar is not affected by this change.

25 Feb 2011 Jiro Doke

Jiro Doke (view profile)

Dirk-Jan, I really like this tool, but I noticed you used "imshow" which is a function from Image Processing Toolbox. Can you change that to use the "image" command instead? In the meantime, please add Image Processing Toolbox as a requirement.

25 Feb 2011 Y Mehta

I get the following error

??? Undefined function or method 'imshow' for input arguments of type 'uint8'.

Error in ==> menubar>CreatMenuBar at 196

Error in ==> menubar at 95

Error in ==> test>test_OpeningFcn at 67

Error in ==> gui_mainfcn at 221
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in ==> test at 27
gui_mainfcn(gui_State, varargin{:});

Comment only
23 Feb 2011 Y Mehta

21 Dec 2010 1.1

Figure Resize Detection.

22 Dec 2010 1.2

Fixed bug: in subsub-menu

04 Jan 2011 1.3

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

05 Jan 2011 1.4

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

06 Jan 2011 1.7

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

12 Jan 2011 1.8

Now also works with regular callback functions.

Contact us