Give Focus to GUI Window
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jeff
am 8 Sep. 2011
Kommentiert: Petr Kryze
am 12 Jul. 2023
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
0 Kommentare
Akzeptierte Antwort
Paulo Silva
am 8 Sep. 2011
figure(FigHandle) %FigHandle is the handle for the GUI figure
2 Kommentare
Petr Kryze
am 12 Jul. 2023
In MATLAB apps:
figure(app.UIFigure)
placed directly after the line that defocuses the App window.
Weitere Antworten (4)
Jan
am 8 Sep. 2011
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 Kommentare
Kris Hoffman
am 29 Dez. 2020
Bearbeitet: Kris Hoffman
am 29 Dez. 2020
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.
claudio
am 26 Apr. 2018
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 Kommentare
Christoph
am 31 Mai 2019
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
am 19 Jul. 2022
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 Kommentar
Petr Kryze
am 12 Jul. 2023
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).
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!