2017-05-31 71 views
2

将焦点切换到另一个图形后,如何将焦点设置为uifigure将焦点设置到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被引入。

回答

6

这是MathWorks在发布新的UI框架之前实际上具有任何功能的奇怪策略的又一例伤亡事件。当然,新的框架显示了很多的承诺,但它在功能上仍然是旧图形系统的一部分。

Rant旁边,有一个快速的解决方法,可以在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); 

你的身材现在最上面呈现在屏幕上。