4

uifigure焦点切换到不同图形后,如何将焦点设置为 a ?

对于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是引入的时间。

4

1 回答 1

7

这是 The MathWorks 在新 UI 框架真正具有任何功能之前发布它的奇怪策略的又一个受害者。诚然,新框架显示出很多希望,但在功能方面仍远远落后于旧图形系统。

除了咆哮之外,有一个在 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);

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

于 2017-05-31T02:44:22.443 回答