jframe = getjframe(hFigOrComponent)
GETJFRAME retrieves the current figure (gcf)'s underlying Java frame, thus enabling access to all 35 figure callbacks that are not exposed by Matlab's figure.
Notable callbacks include: FocusGainedCallback, FocusLostCallback, KeyPressedCallback, KeyReleasedCallback, MouseEnteredCallback, MouseExitedCallback, MousePressedCallback, MouseReleasedCallback, WindowActivatedCallback, WindowClosedCallback, WindowClosingCallback, WindowOpenedCallback, WindowStateChangedCallback and 22 others.
The returned jframe object also allows access to other useful window features: 'AlwaysOnTop', 'CloseOnEscapeEnabled', 'Resizable', 'Enabled', 'HWnd' (for those interested in Windows integration) etc. Type "get(jframe)" to see the full list of properties.
GETJFRAME(hFig) retrieves a specific figure's underlying Java frame. hFig is a Matlab handle, or a list of handles (not necessarily figure handle(s) - the handles' containing figure is used).
get(getjframe,'ListOfCallbacks'); %display list of supported callbacks
jframes = getjframe([gcf,hButton]); % get 2 java frames, from 2 figures
Bugs and suggestions:
Please send to Yair Altman (altmany at gmail dot com)
This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!
worked for me.
Great work. Thank you for keeping this up to date.
This is very useful. I am using it to control minimizing and maximizing the figure windows. I know the potential is much greater.
Fix for R2014b (HG2)
Fix for R2011b
wrong file was initially uploaded by mistake - now fixed
Inspired: blurFigure - blurs and prevents interaction on a figure window, getHWnd - retrieve the underlying Windows handle for Matlab figure(s), undecorateFig - remove/restore figure border and title bar, enable/disable entire figure window, setFigTransparency - set figure transparency / fading, TACTICS Toolbox
Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.