View License

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

» Watch video

Highlights from

4.7 | 11 ratings Rate this file 42 Downloads (last 30 days) File Size: 2.54 KB File ID: #42252 Version: 1.4
image thumbnail



Igor (view profile)


17 Jun 2013 (Updated )

WINONTOP allows to trigger figure's "Always On Top" feature

| Watch this File

File Information

WINONTOP allows to trigger figure's "Always On Top" state
* FigureHandle - Matlab's figure handle, scalar
* IsOnTop - logical scalar or empty array
* WinOnTop( hfigure, bool );
* WinOnTop( hfigure ); - equal to WinOnTop( hfigure,true);
* WinOnTop(); - equal to WinOnTop( gcf, true);
* WasOnTop = WinOnTop(...); - returns boolean value "if figure WAS on top"
* IsOnTop = WinOnTop(hfigure,[]) - gets "if figure is on top" property
* java enabled
* figure must be visible
* figure's "WindowStyle" should be "normal"
Written by Igor
2013.06.16 - Initial version
2013.06.27 - removed custom "ishandle_scalar" function call
2015.04.17 - adapted for changes in matlab graphics system (since R2014b)
2016.05.21 - another ishg2() checking mechanism


Figure Window Always On Top, Set Figure Window To Be Always On Top., and Alwaysontop inspired this file.

This file inspired Wind Turbine Simulator.

Required Products MATLAB
MATLAB release MATLAB 8.1 (R2013a)
MATLAB Search Path
Other requirements java
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (26)
22 Feb 2017 Mendi Barel


24 Jan 2017 Vincent Capron

This function is not working, I got this error on line 92 :

Struct contents reference from a non-struct array object.

08 Nov 2016 Utkarsh Saini

24 Sep 2016 Igor

Igor (view profile)

Thanks for the notice! I've just uploaded the fixed version.

Comment only
21 Sep 2016 Jerry

Jerry (view profile)

bug in line 61, should be if ~exist('isOnTop','var'); isOnTop=true; end
otherwise, the On Top Status could not be switched to 'Off'

Comment only
25 Aug 2016 arnold

arnold (view profile)

I use it every day!

06 Jul 2016 Phill Johanson

PERFECT! Works from the box

21 May 2016 Igor

Igor (view profile)

thanks for the notice, I never ran into such versions myself. I've just uploaded a version, with a completely different approach to the handle graphics version check.

Comment only
19 Apr 2016 Sebastian

You should be careful with this test: "if str2double(v.Version) >= 8.4" Because some Matlab versions have two dots in its version, like R2010bSP2 uses "7.11.2".

Comment only
19 Dec 2015 Alessandro Russo


20 Oct 2015 Kelly Kyriakou


17 Apr 2015 Igor

Igor (view profile)

I've just updated the submission, so now it should work in either case: >=R2014b and <=R2014a , without any modification.
I'm sorry for not doing this for so long..

Michael Hubatka,
Alessandro Russo,
Many thanks for your suggestions!
It looks like Mathworks is going to add more modifications to their graphics system... So, it looks like it is hard to predict, which functionality would be removed in the following versions and which would not...

Comment only
02 Dec 2014 Michael Hubatka


instead of

worked for me.

Comment only
24 Oct 2014 Alessandro Russo

I found the solution myself... just change HG1 to HG2 at line 68 and 71.


ps: HG stands for Handle Graphics and matlab switched from version 1 to version 2 in R2014b (see for instance

Comment only
24 Oct 2014 Alessandro Russo

Hi Igor,

in R2014b WinOnTop doesn't work anymore. I get the following error:

>> WinOnTop
Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks web site.
> In WinOnTop at 64
No appropriate method, property, or field fHG1Client for class com.mathworks.hg.peer.HG2FigurePeer.

Error in WinOnTop (line 68)
WasOnTop = jFrame.fHG1Client.getWindow.isAlwaysOnTop;

Can you fix it? :-)


Comment only
18 Sep 2014 Kanchibhotla Chandra Sekhar

I want to use this file while in opening function of GUI, But i am getting error that Figure is not visible. I can i make the GUI on top using opening function

29 Jul 2014 Jerry

Jerry (view profile)

03 Apr 2014 Bob

Bob (view profile)

I was trying to put an overlay window on top of X-Plane with no success - until I used your code! MANY THANKS.

31 Mar 2014 Ronobir Sarker

How can I find that file?

Comment only
27 Jun 2013 Igor

Igor (view profile)

Thanks, Christine !

Comment only
27 Jun 2013 Mark

Mark (view profile)

Hi Igor,
I'm having trouble getting the code to work. Should the file be placed in the active directory? I also get an undefined function error for 'ishandle_scalar'.


Comment only
27 Jun 2013 Christine

Hi Igor,
now it works fine. And I want to repeat the sentence I read so often here: Your program is exactly what I needed. Thanks a lot! :)

27 Jun 2013 Igor

Igor (view profile)

Hi Christine,
thanks for your notice.
It looks like I've made a couple of mistakes in the original code. I've just uploaded a new version. It would appear in a couple of days.

For now, you may just replace
"ishandle_scalar( FigureHandle )"
"isscalar( FigureHandle ) && ishandle( FigureHandle )".

Comment only
26 Jun 2013 Christine

Hello Igor,
I would very like to use your WinOnTop function but I always get an error message because of the ishandle_scalar function that does not seem to exist in my matlab path. Is it possible, that this function does not exist for my version (matlab 7.9 (R2009b)) and was only implemented in a later version? Can I get somehow around using it?


Comment only
20 Jun 2013 Igor

Igor (view profile)

This version is based on
get(handle(gcf),'JavaFrame') in contrast to
get(gcf,'JavaFrame') ... <blah-blah-blah>

Comment only
18 Jun 2013 Igor

Igor (view profile)

This version is based on get(gcf,'JavaFrame') which won’t return “Warning: figure JavaFrame property will be obsoleted in a future release.”, in contrast to get(gcf,'JavaFrame'), but it’s still possible that it would become obsolete in some future release. Though, most probably, there would be other workaround available.
… and

Comment only
27 Jun 2013 1.1

couple of critical fixes

17 Apr 2015 1.2

adapted for changes in matlab graphics system (since R2014b)

21 May 2016 1.3

Another "is using Handle Graphics v2" check mechanism,

21 May 2016 1.3

fixed duplicate license.txt files

21 May 2016 1.3

Trying to fix zip file getting damaged by Mathworks site.

24 Sep 2016 1.4

fixed IsOnTop vs isOnTop bug

Contact us