4.0

4.0 | 4 ratings Rate this file 124 downloads (last 30 days) File Size: 1.8 KB File ID: #14103

Set figure window to be always on top.

by Per-Anders Ekstrom

 

27 Feb 2007 (Updated 27 Feb 2007)

Code covered by BSD License  

Changes the always-on-top window state.

Download Now | Watch this File

File Information
Description

SETALWAYSONTOP(HFIG,TRUE) will make Matlab figure with handle HFIG to be on top of other windows in the OS even though it might not be in focus.

SETALWAYSONTOP(HFIG,FALSE) will put figure back to normal window state.

SETALWAYSONTOP(HFIG) is the same as SETALWAYSONTOP(HFIG,TRUE).

Second boolean argument TRUE/FALSE can also be exchanged to numerical 1/0.
    
Restrictions:
HFIG must have property value: Visible = on.
HFIG must have property value: WindowStyle = normal.
Swing components must be available in the current Matlab session.
    
Example:
    hFig = figure;
    setAlwaysOnTop(hFig,true); % figure is now on top of other windows

Acknowledgements
This submission has inspired the following:
Set figures and scopes to be always on top
MATLAB release MATLAB 7.2 (R2006a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
28 Feb 2007 F Moisy

Simple but very useful. well done.

28 Feb 2007 John D'Errico

I was expecting to give this a good review. So I tried it out, only to see the following:

>> plot(1:5)
>> setAlwaysOnTop(gcf)

??? Error using ==> setAlwaysOnTop
First Arg. Must be a Figure-Handle

Error in ==> setAlwaysOnTop at 54
fJFrame.fFigureClient.getWindow.setAlwaysOnTop(bool);

I'm fairly confident that gcf is a figure handle. ;-)

>> ishandle(gcf)
ans =
     1

I tried the example shown by the author too:

>> h = figure;
>> setAlwaysOnTop(h,true)
??? Error using ==> setAlwaysOnTop
First Arg. Must be a Figure-Handle

Error in ==> setAlwaysOnTop at 54
fJFrame.fFigureClient.getWindow.setAlwaysOnTop(bool);

All testing was done in R2006b. If I have to hazard a guess, there is an undocumented requirement of Windoze to run this utility.

28 Feb 2007 Matthew Whitaker

See setWindowOnTop
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=11684&objectType=FILE

for an implementation that has been tested with R14SP2 through R2006b

28 Feb 2007 Per-Anders Ekström

Comment 1. Thank you.

Comment 2. I have not tested this utility using R2006b, if I had I would have written that under the MATLAB Release. Could be the problem since Mathworks might have modified their graphics code. For me the code works under both "Windoze" and OS X.

I find it very strange that you get caught in the 'fighandle' error check though. The error is only invoked if:
~ishandle(hFig) % this you have already tested.
length(hFig)~=1 % since figure handle is a scalar this cannot be the case.
~strcmp('figure',get(hFig,'Type')) % according to documentation, for figures, Type is always the string 'figure'.

What am I'm missing?

Comment 3. I had no idea that there existed a code that did this thing already, my bad. The "core" in your code does exactly the same thing as mine.

28 Feb 2007 Matthew Whitaker

The trick that I found for setWindowOnTop was to do that Java calls inside awtinvoke which 'invokes the method on the AWT event thread'

This made it a lot more stable. I was not aware of the expose option for drawnow. learn something everyday!!

09 Jul 2007 Reid Pulley

This function worked if I stepped through the code, but not running free - I kept getting this error:

??? Attempt to reference field of non-structure array.

Error in ==> setAlwaysOnTop at 54
fJFrame.fFigureClient.getWindow.setAlwaysOnTop(bool);

I inserted a slight pause in the code and it worked great.

pause( 0.1 );
fJFrame.fFigureClient.getWindow.setAlwaysOnTop(bool);

14 Aug 2009 Christophe Charbu

Well done. Thank you.

I have tested on the (R2007b) (R2008b)
and it works good.

PS: In the release R2008b, a warning occur :
Warning: figure JavaFrame property will be obsoleted in a future release.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
annotation Per-Anders Ekstrom 22 Oct 2008 09:02:09
customization Per-Anders Ekstrom 22 Oct 2008 09:02:09
figure Per-Anders Ekstrom 22 Oct 2008 09:02:09
set Per-Anders Ekstrom 22 Oct 2008 09:02:09
window Per-Anders Ekstrom 22 Oct 2008 09:02:10
always on top Per-Anders Ekstrom 22 Oct 2008 09:02:10
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com