capture focus change of a figure
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
DGM
2024년 11월 10일 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
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!