uigetfile() goes behind main figure
Hi,
uigetfile(), I think, creates a new figure; it has no parent argument. A number of people complained that its dialog window has unexpeced bahaviour in terms of appearance and focus.
I’m calling it from my main figure (created programmatically with uifigure). The uigetfile() dialog opens as a child of MATLAB window, and NOT as a child of my GUI app which is actually calling it. I.e. it opens behind the main app (problem #1); you need to click on Matlab icon to see this dialog, then, once you select file(s) the focus remains with Matlab window, then, to come back to your app (problem #2), again, manually click on your app to give it the focus.
I found one workaround which seems failing in 2021b on Mac–the dialog still opens behind the main calling app:
f2 = figure(‘Visible’,’off’); % create a dummy figure
drawnow; % give it a focus
[file, path] = uigetfile(…); % call this stubborn thing
delete(f2); % delete dummy
% the above does not work on Mac
% then the 2nd workaround, to give focus back to the calling main fig
% it works fine
drawnow;
figure(f); % f is a handle of the main fig, created with uifigure()
Anybody can help to open this dialog on top of the main app?
I’m on MacOS Monterey. It could be OS dependant, I’m afraid.
The thing is: the new figure is spawned inside uigetfile(), and currently uigetfile() has no way to explicitly mention the parent, therefore, I believe it is Java/OS who decides on the ancestor. And at least on Mac it decides to open it in the main Matlab window. Maybe the dummy figure workaround works on Win (or there is no problem #1 on Win in the first place). One can work with Java window manager to change the focus, but this needs to be done right after the appearance of the dialog, i.e. inside the uigetfile(), not before or after its call.
Eventually, I want to compile the app to a standalone. Thus, there will be no Matlab main window. Maybe then it will behave better. What I’m hearing from others is that this appearance/focus behavior is not consitent between App-Design-created vs programmatical, compiled vs in-Matlab, and diff versions.
ThanksHi,
uigetfile(), I think, creates a new figure; it has no parent argument. A number of people complained that its dialog window has unexpeced bahaviour in terms of appearance and focus.
I’m calling it from my main figure (created programmatically with uifigure). The uigetfile() dialog opens as a child of MATLAB window, and NOT as a child of my GUI app which is actually calling it. I.e. it opens behind the main app (problem #1); you need to click on Matlab icon to see this dialog, then, once you select file(s) the focus remains with Matlab window, then, to come back to your app (problem #2), again, manually click on your app to give it the focus.
I found one workaround which seems failing in 2021b on Mac–the dialog still opens behind the main calling app:
f2 = figure(‘Visible’,’off’); % create a dummy figure
drawnow; % give it a focus
[file, path] = uigetfile(…); % call this stubborn thing
delete(f2); % delete dummy
% the above does not work on Mac
% then the 2nd workaround, to give focus back to the calling main fig
% it works fine
drawnow;
figure(f); % f is a handle of the main fig, created with uifigure()
Anybody can help to open this dialog on top of the main app?
I’m on MacOS Monterey. It could be OS dependant, I’m afraid.
The thing is: the new figure is spawned inside uigetfile(), and currently uigetfile() has no way to explicitly mention the parent, therefore, I believe it is Java/OS who decides on the ancestor. And at least on Mac it decides to open it in the main Matlab window. Maybe the dummy figure workaround works on Win (or there is no problem #1 on Win in the first place). One can work with Java window manager to change the focus, but this needs to be done right after the appearance of the dialog, i.e. inside the uigetfile(), not before or after its call.
Eventually, I want to compile the app to a standalone. Thus, there will be no Matlab main window. Maybe then it will behave better. What I’m hearing from others is that this appearance/focus behavior is not consitent between App-Design-created vs programmatical, compiled vs in-Matlab, and diff versions.
Thanks Hi,
uigetfile(), I think, creates a new figure; it has no parent argument. A number of people complained that its dialog window has unexpeced bahaviour in terms of appearance and focus.
I’m calling it from my main figure (created programmatically with uifigure). The uigetfile() dialog opens as a child of MATLAB window, and NOT as a child of my GUI app which is actually calling it. I.e. it opens behind the main app (problem #1); you need to click on Matlab icon to see this dialog, then, once you select file(s) the focus remains with Matlab window, then, to come back to your app (problem #2), again, manually click on your app to give it the focus.
I found one workaround which seems failing in 2021b on Mac–the dialog still opens behind the main calling app:
f2 = figure(‘Visible’,’off’); % create a dummy figure
drawnow; % give it a focus
[file, path] = uigetfile(…); % call this stubborn thing
delete(f2); % delete dummy
% the above does not work on Mac
% then the 2nd workaround, to give focus back to the calling main fig
% it works fine
drawnow;
figure(f); % f is a handle of the main fig, created with uifigure()
Anybody can help to open this dialog on top of the main app?
I’m on MacOS Monterey. It could be OS dependant, I’m afraid.
The thing is: the new figure is spawned inside uigetfile(), and currently uigetfile() has no way to explicitly mention the parent, therefore, I believe it is Java/OS who decides on the ancestor. And at least on Mac it decides to open it in the main Matlab window. Maybe the dummy figure workaround works on Win (or there is no problem #1 on Win in the first place). One can work with Java window manager to change the focus, but this needs to be done right after the appearance of the dialog, i.e. inside the uigetfile(), not before or after its call.
Eventually, I want to compile the app to a standalone. Thus, there will be no Matlab main window. Maybe then it will behave better. What I’m hearing from others is that this appearance/focus behavior is not consitent between App-Design-created vs programmatical, compiled vs in-Matlab, and diff versions.
Thanks uigetfile, uifigure, focus MATLAB Answers — New Questions