How to make uifigure appear on top of Simulink window?

4 次查看(过去 30 天)
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!

采纳的回答

Abhas
Abhas 2025-6-10
编辑:Abhas 2025-6-10
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.
  3 个评论
Nick
Nick 2025-6-10
Thanks, once again, @Abhas!
The "bringToFront" function, as you described, seems to solve my case!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Entering Commands 的更多信息

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by