Code covered by the BSD License  

Highlights from
statusbar

4.95

5.0 | 22 ratings Rate this file 74 Downloads (last 30 days) File Size: 12.1 KB File ID: #14773
image thumbnail

statusbar

by

 

25 Apr 2007 (Updated )

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

| Watch this File

File Information
Description

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.
Syntax:
    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:
    http://UndocumentedMatlab.com/blog/setting-status-bar-text
    http://UndocumentedMatlab.com/blog/setting-status-bar-components

Notes:
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!

Examples:
> 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','off');
> set(sb.TextPanel, 'Foreground',[1,0,0], 'Background','cyan', 'ToolTipText','tool tip...')
> set(sb, 'Background',java.awt.Color.cyan);

Warning:
  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)

Acknowledgements

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

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

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 (41)
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

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

10 Oct 2014 Peter

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

@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.

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: 7.14.0.739 (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

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

@Ippei - use this instead:
s.getComponent(0).setFont(newFont);

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

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.

f=figure;
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.

Thanks,

Ippei

02 Jul 2013 Chong  
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  
03 Oct 2012 Christopher  
02 May 2012 Yair Altman

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

02 May 2012 Yair Altman

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

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:

h=figure;
obj=uicontrol('style','pushbutton','parent',h,'string','test click','callback',@(h1,h2) msgbox(num2str(h1)));
objjava=findjobj(obj);
sb=statusbar('test');
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(FigurePeer.java:2207)
at com.mathworks.hg.peer.FigurePeer.handleUIControlMouseEvent(FigurePeer.java:2234)
at com.mathworks.hg.peer.FigurePeer$FigurePeerNotificationHandler.handleNotification(FigurePeer.java:2845)
at com.mathworks.hg.peer.FigurePeer.handleNotification(FigurePeer.java:2804)
at com.mathworks.hg.peer.AbstractUicontrolPeer$AbstractUicontrolButtondownListener.mouseMoved(AbstractUicontrolPeer.java:1686)
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(PushButtonPeer.java:64)
...

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,

Teo

18 Apr 2012 Les Beckham

Yair

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
com.mathworks.hg.peer.HG1FigurePeer.

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.

Thanks,
Les

08 Mar 2012 Deborah  
13 Oct 2011 Yair Altman

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

05 Jul 2011 Danilo Zanatta

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"?

Thx!

13 Jun 2011 Yair Altman

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.

12 Jun 2011 Kesh Ikuma

Found another bug.

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

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.

12 Jun 2011 Kesh Ikuma

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 Danilo Zanatta

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:

jProgressBar.setVisible(false);

08 Apr 2010 Alex

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

06 Apr 2010 Yair Altman

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.

06 Apr 2010 Alex

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?
Thanks

28 Jan 2010 Squall Mania

Thanks for the quick reply. I appreciate it.

28 Jan 2010 Yair Altman

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

Yair

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.

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

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:

http://www.mathworks.com/support/contact_us/dev/javaframe.html

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 7.6.0.324 (R2008a)

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

06 Apr 2009 Hoi Wong

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

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!

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

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?

Updates
30 Apr 2007

Added internal ProgressBar; clarified main comment

13 Oct 2011

Fix for R2011b

13 Oct 2014

Fix for R2014b

20 Oct 2014

Updated submission title (no code change)

Contact us