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.
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);
existingText = get(statusbar(myHandle),'Text');
Examples customizing the status-bar appearance:
sb = statusbar('text');
set(sb.TextPanel, 'Foreground',java.awt.Color(1,0,0), 'Background',java.awt.Color.cyan, 'ToolTipText','tool tip...')
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)
Yair Altman (2021). statusbar (https://www.mathworks.com/matlabcentral/fileexchange/14773-statusbar), MATLAB Central File Exchange. Retrieved .
@AP - no. You can set a specific statusbar message whenever you want, but you cannot modify the builtin message.
Is there any way to use your function and change MATLAB default 'Busy' status bar text to for example: 'My text, Busy'? So that whenever MATLAB is busy processing it displays 'My text, Busy'.
Works well in R2016b
It appears that in R2017A, the use of statusbar pushes the uicontrols in a figure upwards. Would like to prevent this.
Any suggestions if this can be controlled?
@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.
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?
Ah, I see, it must be:
set( sb.CornerGrip, 'Visible', 1 )
Is this a small bug?
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');
Error using set
Parameter must be scalar.
Error in progresstest (line 2)
Am I missing something here? Is this not the minimum working example?
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..
@Peter - I made a few fixes for R2014b in the latest version.
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!
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!
@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.
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: 126.96.36.1999 (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
Thank you so much! getComponent seems to be yet another good trick to know in MATLAB-Java world.
@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);
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.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.
Would if be possible for the statusbar to use HTML code for writing hyperlinks like in the command window with HTML syntax?
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...
Oldoteo Oldo - don't do this, it doesn't work on many different levels. Simply create a JButton object rather than a Matlab uicontrol.
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
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 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)
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,
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.
@Danilo - the updated version that I uploaded today hides the warning. It should be available here shortly (maybe tomorrow).
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"?
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.
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.
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."
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:
Indeed, the correct handle is the solution. Thanks for the prompt response Yair.
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.
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.
Thanks for the quick reply. I appreciate it.
It is not possible to modify the statusbar's position. But you can use the TooltipWaitbar utility that does what you wanted: http://www.mathworks.com/matlabcentral/fileexchange/26284-tooltip-waitbar
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!
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 !
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:
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 188.8.131.524 (R2008a)
Is there an alternative to JavaFrame function that will be supported in future releases?
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!
i can't seem to get it working... i want to implement it in a GUI, but how en where do i place what?
Straight forward to include and very nice!
You can control statusbar visibility without destroying it as follows: statusbarHandle.getParent.setVisible(0); %0/1
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?
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!