Hi everybody,
I have programmed a function that starts off with a set of instructions on a GUI, and the user clicks a button to indicate they've read the instructions. After they click the button, the Matlab command line interface comes up asking them to type in their name. After they type in their name and hit enter, I want the GUI to pop back into view instead of having to manually bring up the window. Is there some sort of focus property that I can set to bring the focus back to the GUI window?
Jeff

 채택된 답변

Paulo Silva
Paulo Silva 2011년 9월 8일

2 개 추천

figure(FigHandle) %FigHandle is the handle for the GUI figure

댓글 수: 2

Jeff
Jeff 2011년 9월 8일
figure(hObject) generates the error:
"Requested figure handle in use by another object"
This line of code is executed inside a separate function which is called by a callback function (a button callback function which responds to the user indicating they've read the instructions) in the GUI function. I should note that hObject and handles are both passed into the separate function.
In MATLAB apps:
figure(app.UIFigure)
placed directly after the line that defocuses the App window.

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

추가 답변 (4개)

Jan
Jan 2011년 9월 8일

8 개 추천

Unfortunately "figure(FigHandle)" does not work reliably in opposite to the documentation. E.g. a pressed button can keep the keyboard focus. Therefore I've added this code to all callback of my buttons:
set(ButtonH, 'Enable', 'off');
drawnow;
set(ButtonH, 'Enable', 'on');
Then the figure gets the focus. Another solution is the FEX: WindowAPI, which allows to move the focus also.

댓글 수: 5

Sean de Wolski
Sean de Wolski 2011년 9월 8일
++ THAT IS GENIUS!!
(sorry for the scream, I've been looking for a solution to that for quite some time)
Jan
Jan 2011년 9월 8일
See also: http://www.mathworks.com/matlabcentral/newsreader/view_thread/235825 and http://www.mathworks.com/matlabcentral/answers/555-controlling-background-color-of-selected-uicontrol-popup .
Charles
Charles 2016년 5월 12일
Jan:
5 years later, and this helped me. Thanks!
Jenny Lu
Jenny Lu 2018년 8월 3일
Thank you! A solution to my problems for quite some time.
Kris Hoffman
Kris Hoffman 2020년 12월 29일
편집: Kris Hoffman 2020년 12월 29일
I'm using the arrow keys to visually tally events in a video (in lieu of some computer vision algorithm later).
I got it to switch focus away from the button, but to where? Right now I STILL have to click some blank space in a panel or elswhere to begin using the keyboard.

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

Jeff
Jeff 2011년 9월 8일

1 개 추천

figure(FigHandle) was the correct approach, where FigHandle is the title of your figure.
claudio
claudio 2018년 4월 26일

1 개 추천

You can access directly to java handle and set focus request
% warning off MATLAB:HandleGraphics:ObsoletedProperty:JavaFrame
jFig = get(hFig,'JavaFrame');
jFig.requestFocus
In this way you have not to force enable property of your uicontrols

댓글 수: 2

Mohammad Askari
Mohammad Askari 2018년 6월 6일
Superb! This is much faster than using drawnow. Thanks.
With 2017b this does not work for me, furthermore I get this warning:
Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks web site.
In my case
figure(FigHandle)
did the job.

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

Bernard
Bernard 2022년 7월 19일

1 개 추천

figure(app.UIFigure) works from within an app function for me.
I have to use this often when calling uigetfile because after selecting a file, the focus does not return to the app even though that was the previously active window.

댓글 수: 1

I can confirm this works perfectly in MATLAB apps as of July 2023. Just put the
figure(app.UIFigure)
line directly after the command that defocuses the app window (uigetfile and such).

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

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

질문:

2011년 9월 8일

댓글:

2023년 7월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by