How to make uifigure appear on top of Simulink window?

Hi,
I'm developing a toolbox for Simulink, which also has some UI - i.e. I'm creating an uifigure for a preferences dialog, triggered from the Toolstrip.
In later versions of MATLAB, the hierarchy of windows for MATLAB and Simulink seems to be changed, and since all uifigures belong to MATLAB, and not to Simulink, created figures appear behind Simulink.
In previous versions of MATLAB I've used
figure(myFigure)
to ensure that the dialog is shown on the top, but this doesn't help anymore (better to say, it works on Mac, doesn't work on Windows).
I found a workaround, but it is rather strange and is not reflected in any documentation: if I open a uiprogressdlg with parent set to the myFigure, then the figure will be brought to the front too. So, I just open a uiprogressdlg and delete it immediately to ensure that myFigure is shown to the user.
Is there any better solution, which doesn't require such workaround?
Thank you!

 Accepted Answer

Abhas
Abhas on 10 Jun 2025
Edited: Abhas on 10 Jun 2025
Hi @Nick,
There are cleaner, more supported alternatives to ensure your "uifigure" stays on top of Simulink on Windows:
  • MATLAB now supports ensuring your uifigure remains above all other windows by setting its "WindowStyle" property:
fig = uifigure;
% Ensure the figure floats above everything, including Simulink
fig.WindowStyle = 'alwaysontop';
  • If "alwaysontop" creates conflicts, a solid workaround is toggling visibility. This leverages the "Visible" property to force the OS to re-layer your window. Call this after creating your dialog either manually or right after "uifigure()" and it reliably brings the figure forward on Windows.
function bringToFront(fig)
drawnow;
fig.Visible = 'off';
fig.Visible = 'on';
end
I hope this resolves your query.

4 Comments

Thanks, @Abhas for your support!
Your response is very valuable, as it brings my attention to several points.
Yeah, 'alwaysontop' does produce some conflicts, e.g. uialerts appear behind those figures and it also changes behavior of other applications running (non-MATLAB apps will be behind those windows - which could be inconvenient for the end-users, as some of my figures have long life-cycle on the screen).
So, let me check the second variant!
Actually, I'm using visibility of the figures - e.g. when I open the figure, I remember/restore its position from the previous session. Therefore to prevent the figure visually "jumping" on the screen, I'm hiding it during the creation, and showing it at the end with setting 'Visibility=on'. Though I didn't use 'drawnow' before setting the parameters.
Since all the details seem to be relevant, let me put here more exact excerpt from the code, of how do I handle the figures:
% showing some progress indication, that a dialog is opening (uifigure
% creation can take time, and when it happens in invisible form, user can
% get confusion)
wb = waitbar(0, message, 'Name', title); % appears on top on all platforms.
% I'm using waitbar instead of the uiprogressdlg, as when the parent is invisible, the uiprogressdlg will be invisible too
% create the figure with Visible off
obj.mainFigure = uifigure('Name', obj.tag, 'Visible', 'off', 'Tag', obj.tag, 'CloseRequestFcn', @obj.closeDialogFcn, 'KeyPressFcn', @obj.keyPressedFcn);
...
% set the position, while still hidden
obj.mainFigure.Position = getpref('RqDialogPositions', preftag);
...
set(obj.mainFigure, 'Visible', 'on'); % Here figure appears in the background of Simulink on Windows
delete(wb); % closing the progress indicator
let me try to play with the 'drawnow' and accept your response ASAP (I'm developing on Mac, and need to start my Windows environment to compare :-))
Thanks, once again, @Abhas!
The "bringToFront" function, as you described, seems to solve my case!
After a year in R2026a.U3 I found, that the solution is not as solid, as I thought.
For my scenario I've applied the workaround with progress indication, which I described above.
Leaving this comment just as a note if somebody will face the same.
---
Longer story:
Reproduction scenario is relatively complicated, and I tested this so far on Mac only:
2 monitors (with one monitor it behaves as expected!):
  • on one is Simulink window and the dialogs, I'd like to bring to top.
  • on second monitor is MATLAB main app.
Click to focus on Simulink and then MATLAB main window. Dialogs are hidden behind the Simulink window.
Now I trigger toolstrip action in Simulink, which executes "bringToFront" function for a dialog.
Result: the dialog appears on top once every 4-5 times clicks, in other words majority of attempts the dialog remains in background.
Very likely, it is related to the fact, that after triggering Toolstrip, there are some activities in Simulink, which grab focus back. I observe:
  • Clicking toolstrip - Simulink get's focus
  • MATLAB main window gets focus likely as 'bringToFront' activates it.
  • Simulink loses focus, and redraws some components - e.g. Properties Inspector is removing the editors.
I tried to play with style='alwaysontop' (like assign this style to bring the dialog on top, then set it back to 'normal' to allow the user using windows stack as he wants) - no, doesn't work either, as soon as I assign 'normal', the dialog goes background.

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Programmatically in Help Center and File Exchange

Products

Release

R2025a

Asked:

on 9 Jun 2025

Commented:

on 12 Jun 2026

Community Treasure Hunt

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

Start Hunting!