将焦点设置到 uifigure window

Set focus to a uifigure window

焦点切换到其他图形后,如何将焦点设置到 uifigure

对于 uicontrol,可以将焦点设置在其子元素之一上。例如:

% create a new uicontrol text label
h = uicontrol('style','text','string','This is my figure');
% create a figure to switch the focus
figure;
% switch back
uicontrol(h)

但是,对于 uifigure,采用类似的代码只会创建一个新的 uifigure

一些代码供您尝试:

% create a new uifigure
h = uifigure('Name','This is my figure');
% create a new uilabel as a child of uifigure
lh = uilabel(h)
% create a figure to switch the focus
figure;
% this creates a new uifigure then switch back
uifigure(h)
% this creates an error as the first input argument must be a valid parent for uilabel
uilabel(lh)

感谢任何想法、见解或贡献。

请注意,您的 Matlab 版本应至少为 2016a,因为这是引入 uifigure 的时间。

这是 MathWorks 在新 UI 框架实际具有任何功能之前发布的怪异策略的又一个牺牲品。诚然,新框架展示了很多前景,但它在功能方面仍然 lags far behind 旧图形系统。

撇开胡言乱语,有一个在 R2017a 中测试良好的快速解决方法:切换 uifigure 的可见性,从而使其脱颖而出。这是一个基本示例:

function uifigurepop(uifigurehandle)
drawnow;
uifigurehandle.Visible = 'off';
uifigurehandle.Visible = 'on';
end

其中,如果我们将其带入示例代码:

% create a new uifigure
h = uifigure('Name','This is my figure');
% create a new uilabel as a child of uifigure
lh = uilabel(h)
% create a figure to switch the focus
figure;
% this creates a new uifigure then switch back
uifigure()
uifigurepop(h);

您的图形现在呈现在屏幕的最上方。