Code covered by the BSD License  

Highlights from
MenuBar

5.0

5.0 | 2 ratings Rate this file 26 Downloads (last 30 days) File Size: 13.16 KB File ID: #29760
image thumbnail

MenuBar

by Dirk-Jan Kroon

 

17 Dec 2010 (Updated 12 Jan 2011)

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
Description

 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');

MATLAB release MATLAB 7.11 (2010b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
23 Feb 2011 Y Mehta  
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
    data.menuitems(i).HandleImshow=imshow(barimage,'Parent',data.menuitems(i).Handle);

Error in ==> menubar at 95
        CreatMenuBar(uimenuhandle,C(i),Pos,figure_handle);

Error in ==> test>test_OpeningFcn at 67
menubar;

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{:});

25 Feb 2011 Jiro Doke

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.

Please login to add a comment or rating.
Updates
21 Dec 2010

Figure Resize Detection.

22 Dec 2010

Fixed bug: in subsub-menu

04 Jan 2011

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

05 Jan 2011

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

06 Jan 2011

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

12 Jan 2011

Now also works with regular callback functions.

Tag Activity for this File
Tag Applied By Date/Time
menubar Dirk-Jan Kroon 17 Dec 2010 13:13:41
uipanel Dirk-Jan Kroon 17 Dec 2010 13:13:41
uicontextmenu Dirk-Jan Kroon 17 Dec 2010 13:13:41
menu bar Dirk-Jan Kroon 17 Dec 2010 13:13:41
menu Dirk-Jan Kroon 17 Dec 2010 13:13:41
bar Dirk-Jan Kroon 17 Dec 2010 13:13:41
figure Dirk-Jan Kroon 17 Dec 2010 13:13:41
design Dirk-Jan Kroon 17 Dec 2010 13:13:41
menus Dirk-Jan Kroon 17 Dec 2010 13:13:41
guide Dirk-Jan Kroon 17 Dec 2010 13:13:41
gui Dirk-Jan Kroon 17 Dec 2010 13:13:41
uicontrol Dirk-Jan Kroon 17 Dec 2010 13:13:41
bar carolina gialdi 18 Jan 2011 12:33:04
potw Lindsay Coutinho 18 Feb 2011 13:44:33
pick of the week Lindsay Coutinho 18 Feb 2011 13:44:33

Contact us at files@mathworks.com