필터 지우기
필터 지우기

GUI figure focus

조회 수: 18 (최근 30일)
tomas
tomas 2012년 3월 23일
댓글: undefined undefined 2021년 4월 28일
Hello, I have a problem with focusing of the main figure in my GUI. My keyboard shortcuts works properly until I use the fill command for adding a patch object to my plot. While this object exists I can't use keyboard shortcuts, but immediately after deleting the patch object I'm able to use all shortcuts again. I've read discusion about similar problems of other users and I've tried set(hObject, 'enable', 'off'); drawnow; set(hObject, 'enable', 'on');
but it doesn't work for this.
function ReleaseFocus(fig) mentioned in one answer has no effect as well.
Any ideas how to solve this problem?
Thanks in advance.
Tom
  댓글 수: 1
Oleg Komarov
Oleg Komarov 2012년 3월 23일
Please post a synthetic version of your gui and which keyboard shortcuts you're trying to gian focus on the figure.

댓글을 달려면 로그인하십시오.

답변 (3개)

Jan
Jan 2012년 3월 23일
Actually this should move the focus to the figure:
figure(gcf)
Unfortunately this does not work - at least since Matlab 5.3.
The temporary disabling of an uicontrol, which is currently focussed, move the focus to its parent. If your GUI contains an uicontrol you can try this, after the drawing:
hObject = HandleOfTheButton; % Set accordingly
uicontrol(hObject); % Yes, this works correctly!
set(hObject, 'enable', 'off');
drawnow;
set(hObject, 'enable', 'on');
This moves the focus to the button (or whatever) at first and to the figure afterwards.
But a problem remains: Whenever you click on the axes object, it gets the focus back and the figure's KeyPressFcn is not active anymore. Then it will be more reliable, if you add the KeyPressFcn to all objects, which allows to set this property.
The must be a Java callback, which allows to activate the figure, but I cannot test this currently:
jPeer = get(handle(gcf), 'JavaFrame');
jAxis = jPeer.getAxisComponent;
jWindow = jPeer.fFigureClient.getWindow;
Now you can study the methods:
methods(jPeer);
methods(jAxis);
methods(jWindow);
Is there a "setFocus()" routine? If so and it works:
This is undocumented and you have to care for the fact, that this might not work with other Matlab releases. So include the command in a TRY-CATCH block and write a meaningful warning message if it fails.
[EDITED] It is:
jPeer = get(handle(gcf), 'JavaFrame')
jPeer.getAxisComponent.requestFocus
[EDITED 2] Please send an enhancement request to TMW, if you want figure(gcf) to set the focus reliably.
  댓글 수: 1
undefined undefined
undefined undefined 2021년 4월 28일
How can I know which figure is currently in focus ?
Jan , U gr8 !
TNX for all Ans' !

댓글을 달려면 로그인하십시오.


Sean de Wolski
Sean de Wolski 2012년 3월 23일
What is hObject in the above line? I am going to hazard guess that it is not the axes. Can you put a break point right before you do the:
set(hOb...
And then:
get(hObject,'type')
  댓글 수: 6
Jan
Jan 2012년 3월 23일
Some of the suggested methods do not work in Matlab 2008a. Which version are you using, tomas?
tomas
tomas 2012년 3월 26일
I use Matlab 7.11.0 (R2010b) version.
I made another testGUI because the original one is quite complicated for posting it here. I put there only necessary components to demonstrate where the problem is and the script behaves totaly different and I'm completely confused :-). I draw there the patch object in the same way and shortcuts works even while the patch object is still active. The only problem with the focus is after I delete the patch object. May be there is any connection why it is happen, but I'm not able to find out where.
How can I post the testGUI and data? Is there any possibility to do it within this site or just use any common upload site?
Thank you guys for your help.

댓글을 달려면 로그인하십시오.


Stefan Karlsson
Stefan Karlsson 2015년 2월 5일
Seems this is still an issue, here is my solution quick fix:
%takes any active uiobject as input, and returns keyboard focus back to parent window
function ReleaseFocusFromAnyUI(uiObj)
set(uiObj, 'Enable', 'off');
drawnow update;
set(uiObj, 'Enable', 'on');
this works well on a couple of systems I tried it on. The addition of "update" to the drawnow command makes it execute faster on my systems, and prevents the drawnow to issue any new events that makes callbacks execute (a hidden issue with above suggestion).
I put this at the very front of my callbacks.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by