WINONTOP allows to trigger figure's "Always On Top" state
% INPUT ARGUMENTS:
# figureHandle - Matlab's figure handle, scalar
# isOnTop - logical scalar or empty array
% USAGE:
* WinOnTop( hfigure, true ); - switch on "always on top"
* WinOnTop( hfigure, false ); - switch off "always on top"
* 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,[]) - get "if figure is on top" property
For Matlab windows, created via `hf=uifigure()` use `uifigureOnTop()`, see:
https://www.mathworks.com/matlabcentral/fileexchange/73134-uifigureontop
% LIMITATIONS:
* java enabled
* figure must be visible
* figure's "WindowStyle" should be "normal"
* figureHandle should not be casted to double, if using HG2 (R2014b+)
Igor (2021). WinOnTop (https://github.com/i3v/WinOnTop), GitHub. Retrieved .
Inspired by: Figure Window Always on Top, Set figure window to be always on top., ALWAYSONTOP
Inspired: uifigureOnTop, WIND TURBINE SIMULATOR
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
There is now a warning when this function is executed.
`Warning: The JavaFrame figure property will be removed in a future release. For more information, see Recommendations for Java and ActiveX Users
on mathworks.com.
> In WinOnTop (line 79) `
Works well and well documented. Thanks Igor
Nice !
Exactly what I was looking for, this is great.
@Alexander B. ,
No, AFAIU.
is there a way to specify a process so that the figure is only on top of that process and not other windows?
nice
This function is not working, I got this error on line 92 :
Struct contents reference from a non-struct array object.
Jerry,
Thanks for the notice! I've just uploaded the fixed version.
bug in line 61, should be if ~exist('isOnTop','var'); isOnTop=true; end
otherwise, the On Top Status could not be switched to 'Off'
I use it every day!
PERFECT! Works from the box
Sebastian,
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.
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".
:-)
Great!!!
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...
using
javax.swing.SwingUtilities.getWindowAncestor(jFrame.getAxisComponent);
instead of
jFrame.fHG2Client
worked for me.
I found the solution myself... just change HG1 to HG2 at line 68 and 71.
Ale
ps: HG stands for Handle Graphics and matlab switched from version 1 to version 2 in R2014b (see for instance http://undocumentedmatlab.com/blog/customizing-axes-rulers).
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? :-)
Ciao
Ale
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
I was trying to put an overlay window on top of X-Plane with no success - until I used your code! MANY THANKS.
How can I find that file?
Thanks, Christine !
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'.
Thanks,
Mark
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! :)
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 )"
with
"isscalar( FigureHandle ) && ishandle( FigureHandle )".
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?
Thanks,
Christine
oops...
Edit:
This version is based on
get(handle(gcf),'JavaFrame') in contrast to
get(gcf,'JavaFrame') ... <blah-blah-blah>
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.
See
http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/
… and
https://www.mathworks.com/matlabcentral/newsreader/view_thread/246453#656957