Code covered by the BSD License  

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

» Watch video

Highlights from

5.0 | 25 ratings Rate this file 43 Downloads (last 30 days) File Size: 12.3 KB File ID: #14773 Version: 1.6
image thumbnail



Yair Altman (view profile)


25 Apr 2007 (Updated )

set/get status bar(s) for GUI figures & Matlab desktop

| Watch this File

File Information

statusbar sets the status-bar text of the Matlab desktop or a figure. statusbar accepts arguments in the format accepted by the sprintf function and returns the statusbar handle(s), if available.
    statusbarHandle = statusbar(handle, text, sprintf_args...)
statusbar(text, ...) sets the status bar text for the currently selected figure. If no figure is selected, then one will be created. Note that figures with 'HandleVisibility' turned off will be skipped. In these cases, simply pass their figure handle as first argument.
statusbar(handle, ...) sets the status bar text of the figure handle (or the figure which contains handle). If the status bar was not yet displayed for this figure, it will be created and displayed. If text is not supplied, then any existing status bar is erased, unlike statusbar(handle, '') which just clears the text.
statusbar(0, ...) sets the Matlab desktop's status bar text. If text is not supplied, then any existing text is erased, like statusbar(0, '').
statusbar([handles], ...) sets the status bar text of all the requested handles.
statusbarHandle = statusbar(...) returns the status bar handle for the selected figure. The Matlab desktop does not expose its statusbar object, so statusbar(0, ...) always returns []. If multiple unique figure handles were requested, then statusbarHandle is an array of all non-empty status bar handles.
Technical description:
1) The format statusbarHandle = statusbar(handle) does NOT erase any existing statusbar, but just returns the handles.
2) The status bar is 20 pixels high across the entire bottom of the figure. It hides everything between pixel heights 0-20, even parts of uicontrols, regardless of who was created first!
   statusbar; % delete status bar from current figure
   statusbar(0, 'Desktop status: processing...');
   statusbar([hFig1,hFig2], 'Please wait while processing...');
   statusbar('Processing %d of %d (%.1f%%)...',idx,total,100*idx/total);
   statusbar('Running... [%s%s]',repmat('*',1,fix(N*idx/total)),repmat('.',1,N-fix(N*idx/total)));
   existingText = get(statusbar(myHandle),'Text');
Examples customizing the status-bar appearance:
  sb = statusbar('text');
  set(sb.CornerGrip, 'visible',false);
  set(sb.TextPanel, 'Foreground',java.awt.Color(1,0,0), 'Background',java.awt.Color.cyan, 'ToolTipText','tool tip...')
  set(sb, 'Background',java.awt.Color.cyan);
  Additional examples are provided in the utility's help section.
  This code heavily relies on undocumented and unsupported Matlab
  functionality. It works on Matlab 7+, but use at your own risk!
Bugs and suggestions:
  Please send to Yair Altman (altmany at gmail dot com)


Findjobj Find Java Handles Of Matlab Graphic Objects and Uicomponent Expands Uicontrol To All Java Classes inspired this file.

This file inspired Progress Dialog, Statusbar Timer, Tabular Expression Toolbox, Lynx Matlab Toolbox, and C Progress.

MATLAB release MATLAB 7.4 (R2007a)
MATLAB Search Path
Other requirements Tested on Matlab 6.0-7.4. In Matlab 6.0 (R12) figure statusbars are not supported - only desktop statusbar. Please report any other compatibility issues.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (46)
01 Oct 2015 Peter Beemiller  
22 Mar 2015 Yair Altman

Yair Altman (view profile)

@Mark - it is not a bug in the utility, it is simply a change in the way that Matlab uses to set logical flags in Java objects ('on'=>true, 'off'=>false) since 2012 or 2013 I think (I don't remember which Matlab release exactly). Another change occurred in the way that colors are interpreted by Matlab.

I've now updated the usage examples accordingly.

Comment only
03 Mar 2015 Massimiliano

Hi Yair,
thank you for your statusbar.
I have created and built with mcc a Matlab GUI with Matlab R2013b 32 bit on Windows XP 32 bit and all is ok, also using it on Windows 7 64 bit. Then I have tried to add to my GUI your statusbar and it works well, but if I try to use my GUI with the statusbar on any pc with Windows 7 64 bit the GUI crashes just when the statusbar is in use.
Please, could you kindly verify if there is a bug in the statusbar code, related to Windows 7 64 bit?

22 Jan 2015 Mark

Mark (view profile)

Ah, I see, it must be:

set( sb.CornerGrip, 'Visible', 1 )

Is this a small bug?


Comment only
22 Jan 2015 Mark

Mark (view profile)

Hi Yair,

Thanks for this wonderful function!

I try to use the progress bar, but the 'set' function generates an error (I'm on MATLAB 2014b):

sb = statusbar('text');
set(sb.CornerGrip, 'visible','off');


Error using set
Parameter must be scalar.

Error in progresstest (line 2)
set(sb.CornerGrip, 'visible','off');

Am I missing something here? Is this not the minimum working example?

Kind regards,

18 Oct 2014 Bruce W.

Hi Yair,
Enjoy the book, and the various submissions.
I just updated to 2014b, and find that the latest version of statusbar seems to make my GUI shift up instead of overwriting it, but when I move it ever so slightly, it moves the GUI back to as expected, and stays there...? Haven't looked into it yet, but thought I should mention it on a very useful piece of code..

13 Oct 2014 Yair Altman

Yair Altman (view profile)

@Peter - I made a few fixes for R2014b in the latest version.

Comment only
10 Oct 2014 Peter Beemiller

Hi Yair, statusbar will require a few changes for R2014b. I've edited it for myself, as statusbar is awesome and I can't live without it!

20 Aug 2014 Eddie Smo  
20 Aug 2014 Eddie Smo

Hi Yair,
I've been using and liking this app for a few weeks now. Good job!

One issue I have encountered though, is when I tried to run my code in matlab 2012b, it crashed it (matlab stopped responding).

It's quite strange: when I run it in debug mode, line by line, it doesn't crash, but if I just let it run (f5), it kills my matlab.

The problem seems to be in the functions that change the text panel background color and the statusbar border color. Maybe it's because I run it in a loop and something Java related is still in process when the next call comes?

Anyway, the bug doesn't exist in 2013b, and I have found ways around it, so kudos to you!

19 May 2014 Andrei Veldman  
16 Feb 2014 Yair Altman

Yair Altman (view profile)

@Michael - perhaps you're running this on an invisible figure, or within the GUIDE-generated *_OpeningFcn, or before the figure window had enough time to actually render onscreen.

Comment only
24 Jan 2014 Michael

Doesn't work in Matlab 7.14 (R2012a).

The method jFigPanel.getComponent(0).getRootPane doesn't return anything and so the jRootPane variable always remains empty, which results in an "Attempt to reference field of non-structure array" error.

System info (output of 'ver'):
MATLAB Version: (R2012a)
Operating System: Microsoft Windows 7 Version 6.2 (Build 9200) //though actually I run Windows 8.1 (6.3.9600)
Java Version: Java 1.6.0_17-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode

Comment only
04 Nov 2013 Ippei Kotera

Hi Yair,
Thank you so much! getComponent seems to be yet another good trick to know in MATLAB-Java world.

02 Nov 2013 Yair Altman

Yair Altman (view profile)

@Ippei - use this instead:

(the displayed label is actually a sub-component of s, so you need to use getComponent(0) )

@Thierry - the same answer can also help you:

set(s.getComponent(0), 'Text','<html><a href="">click me!', 'MouseClickedCallback',@myCallbackFcn);

Comment only
01 Nov 2013 Ippei Kotera

Thanks for another useful tool.

Is there a way to change the font of the text in statusbar? I tried following code but didn't work for some reasons.

s=statusbar(f, '');
s.setFont(java.awt.Font('Consolas', java.awt.Font.PLAIN, 12));
s.setText('The font doesn''t change');

Using your findjobj, I noticed that the statusbar text object is called MJStatusBar$1 and I could change the font from your findjobj GUI, but I don't know how to access this class programmatically.



02 Jul 2013 Chong

Chong (view profile)

05 Nov 2012 Thierry Dalon

Would if be possible for the statusbar to use HTML code for writing hyperlinks like in the command window with HTML syntax?

18 Oct 2012 Jon

Jon (view profile)

03 Oct 2012 Christopher  
02 May 2012 Yair Altman

Yair Altman (view profile)

Les Beckham - I do not believe that docked figures are currently supported (i.e., the status is updated, but some warnings/errors are displayed. I'll fix this someday if and when I have some free time...

Comment only
02 May 2012 Yair Altman

Yair Altman (view profile)

Oldoteo Oldo - don't do this, it doesn't work on many different levels. Simply create a JButton object rather than a Matlab uicontrol.

Comment only
02 May 2012 oldoteo Oldo

Thanks Yair,
you're doing a great job.
I'm trying to add components to your statusbar without dealing with the creation of Java objects directly. I'd like to receive a set of existing Matlab handles (pushbuttons, sliders,...) and add them to the statusbar:

obj=uicontrol('style','pushbutton','parent',h,'string','test click','callback',@(h1,h2) msgbox(num2str(h1)));
sb.add(objjava,'East'); %Puts a similar object in the statusbar but throws an error on mouse motion
sb.setText('test text');

but when moving the mouse on the new button (whereas the existing one is still on the Matlab window) it raises the error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.mathworks.hg.peer.FigurePeer.translateComponentPointToFigurePoint(
at com.mathworks.hg.peer.FigurePeer.handleUIControlMouseEvent(
at com.mathworks.hg.peer.FigurePeer$FigurePeerNotificationHandler.handleNotification(
at com.mathworks.hg.peer.FigurePeer.handleNotification(
at com.mathworks.hg.peer.AbstractUicontrolPeer$AbstractUicontrolButtondownListener.mouseMoved(
at java.awt.AWTEventMulticaster.mouseMoved(Unknown Source)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at com.mathworks.hg.peer.PushButtonPeer$1.processEvent(

I think somehow the problem is that the object has to be actually cloned but I can't see any clone method of objjava.
Moreover, if I delete the Matlab object (delete(obj)) the Java object remains in the status bar but has no callback property set (even via uiinspect and findjobj).
Do you have any idea?

Thank you for your help,


18 Apr 2012 Les Beckham


Have you tried this updated version on a figure that is docked? I receive the following error (in 2011b) when I run a simple test on a docked figure:

>> statusbar(gcf, 'This is another test')
Error using statusbar>setFigureStatus (line 259)
error updating status text for figure Figures - Figure 12: Ground track: No
appropriate method, property, or field fFigureClient for class

Error in statusbar (line 153)
thisStatusbarObj = setFigureStatus(rootHandles(rootIdx),
deleteFlag, updateFlag, statusText);

Note that the text does show up in the status bar of the dock container but I still get the error.


Comment only
08 Mar 2012 Deborah  
13 Oct 2011 Yair Altman

Yair Altman (view profile)

@Danilo - the updated version that I uploaded today hides the warning. It should be available here shortly (maybe tomorrow).

Comment only
05 Jul 2011 daniloz

Matlab 7.10.0 (R2010a) and later versions give me the following warning:

Warning: figure JavaFrame property will be obsoleted in a future release. For more information see
the JavaFrame resource on the MathWorks Web site.
> In statusbar>setFigureStatus at 202
In statusbar at 148

Any chance this can be "fixed"?


Comment only
13 Jun 2011 Yair Altman

Yair Altman (view profile)

Kesh - all Java-based functionality in Matlab (not just this StatusBar utility) requires the figure window to be visible and fully-rendered.

To remove the 'Property name already in use' annoyance, simply put a comment (%) at the beginning of line #263 (lasterr). This has no effect on the functionality.

Comment only
12 Jun 2011 Kesh Ikuma

Kesh Ikuma (view profile)

Found another bug.

fig = figure('Visible','off');

errors out in the setFigureStatus subroutine. I guess that the figure is not instantiated yet if it's made invisible at the time of creation.

Comment only
12 Jun 2011 Kesh Ikuma

Kesh Ikuma (view profile)

Yair, thanks for another great one!

I spotted a minor bug (well, I wouldn't even call it a bug, more of an annoyance).

If you run "statusbar(gcf,'test')" twice, the second call displays 3 "ans" in Command Window. They all say "ans = Property name already in use."

29 Mar 2011 daniloz

First, thanks for the nice tool!!!!

Just to report a warning in R2010b:

Warning: Possible deprecated use of set('Visible','off') on Java boolean property:
use jobj.setVisible(false) instead.

Fixed by changing line 229 of statusbar.m to:


08 Apr 2010 Alex

Alex (view profile)

Indeed, the correct handle is the solution. Thanks for the prompt response Yair.

Comment only
06 Apr 2010 Yair Altman

Yair Altman (view profile)

Alex - in your button callback, after you create the new figure, pass its handle as the first input argument to the statusbar utility. If you don't, statusbar uses gcf (the current figure handle) which is still pointed to your original figure.

Comment only
06 Apr 2010 Alex

Alex (view profile)

Great tool! One request for assistance:
In my GUI I need to load a different figure each time I press a button; the figure should contain a statusbar. However the statusbar is loaded only in the first figure.

Any ideas?

28 Jan 2010 Squall Mania

Thanks for the quick reply. I appreciate it.

28 Jan 2010 Yair Altman

Yair Altman (view profile)

It is not possible to modify the statusbar's position. But you can use the TooltipWaitbar utility that does what you wanted:


Comment only
28 Jan 2010 Squall Mania

It works like a charm! I have inserted the progress bar on my figure and it worked perfectly. I have one question, is it possible to actually change the position of the progress bar on my figure? I want it to be up and below my pushbutton.

Your help would be greatly appreciated!
Thanks again.

Comment only
08 Oct 2009 Aurelien Queffurust

Tested in R2009b, it works perfectly, the function is really well documented . I used all the customization (toollip, background ...)
It is very good to have a waitbar "docked". Thanks !

24 Jul 2009 Yair Altman

Yair Altman (view profile)

JavaFrame has no alternative. If and when it is discontinued in some future version we shall try to look for alternatives. Until then simply ignore this error by typing:

warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame

Note that even if some future version discontinues JavaFrame, it will still continue to work properly on all prior Matlab versions (including your current version).

If you find JavaFrame to be useful for your needs, please consider letting MathWorks know about this in the webpage they dedicated for just this purpose:

Comment only
24 Jul 2009 Stefano Gianoli

Very nice implementation. Though I receive this warning message.:

Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame
resource on the MathWorks Web site.
> In statusbar>setFigureStatus at 202
In statusbar at 148

I am using MATLAB Version (R2008a)

Is there an alternative to JavaFrame function that will be supported in future releases?

Comment only
06 Apr 2009 Hoi Wong

Hoi Wong (view profile)

Great tool. My project uses a lot of your enableDisableFig and stausbar. But it seems like R2009b pops out a lot "Property name already in use" and MCR pops out a lot problems with 'undefined function or variable currentState' in enableDisableFig. Got some time to look at it? Thanks!

11 Dec 2008 Kim

Kim (view profile)

i can't seem to get it working... i want to implement it in a GUI, but how en where do i place what?
Please help!

Comment only
11 Mar 2008 Ralf Hielscher

Straight forward to include and very nice!

09 Aug 2007 Marcus Gualtieri  
05 Jun 2007 Yair Altman

You can control statusbar visibility without destroying it as follows: statusbarHandle.getParent.setVisible(0); %0/1

Comment only
04 Jun 2007 Darik Gamble

This is fantastic. Very clean implementation.

One question: is there a way to turn off the entire statusbar visibility without destroying it or setting the child visibilities?

30 Apr 2007

Added internal ProgressBar; clarified main comment

13 Oct 2011 1.1

Fix for R2011b

13 Oct 2014 1.2

Fix for R2014b

20 Oct 2014 1.3

Updated submission title (no code change)

22 Mar 2015 1.4

Updated usage examples (no changes to the code)

22 Mar 2015 1.5

Updated usage examples (no changes to the code)

22 Mar 2015 1.6

Updated usage examples (no changes to the code)

Contact us