capture focus change of a figure
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
does somebody know how to listen to a focus change of a figure? Yair Altman's blog mentions a way in his blog: http://undocumentedmatlab.com/blog/detecting-window-focus-events but unfortunately this method doesn't work if the figure includes a graphical axis.
Any hint appreciated! Daniel
0 commentaires
Réponses (1)
DGM
le 10 Nov 2024 à 14:05
This is based on the examples given in the comments. I've tested it in R2015b and R2019b, so I'm assuming it would have worked circa 2017. This does not work on docked figures.
% you have a populated figure (has a descendant axes)
hFig = figure;
plot(rand(100,1));
drawnow
% mute the warning
% i don't know which exact version this changed in
warning off 'MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame' % older versions (effective in R2015b)
warning off 'MATLAB:ui:javaframe:PropertyToBeRemoved' % newer versions (effective in R2019b)
% Get the underlying Java reference
jf = get(hFig,'JavaFrame');
jw = handle(jf.getFigurePanelContainer.getTopLevelAncestor,'CallbackProperties');
% set some example focus callbacks
set(jw,'WindowGainedFocusCallback',@(x,y)disp('given focus'));
set(jw,'WindowLostFocusCallback', @(x,y)disp('lost focus'));
That said, I don't know if this still works in modern versions. It fails in the forum editor, though I'm not sure if that's just a forum thing or if the JavaFrame property has finally been removed. Unfortunately, that seems particularly likely.
0 commentaires
Voir également
Catégories
En savoir plus sur Specifying Target for Graphics Output dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!