Ant*_*ony 3 matlab matlab-app-designer
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)
Run Code Online (Sandbox Code Playgroud)
但是,因为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)
Run Code Online (Sandbox Code Playgroud)
任何想法,见解或贡献都表示赞赏.
请注意,您的Matlab版本应该至少为2016a,因为这uifigure是引入的时间.
这是The MathWorks在实际拥有任何功能之前发布新UI框架的奇怪策略的另一个受害者.当然,新框架显示了许多承诺,但在功能方面仍然远远落后于旧的图形系统.
除此之外,还有一个快速的解决方法,在R2017a中测试很好:切换了它的可见性uifigure,这使它脱颖而出.这是一个基本的例子:
function uifigurepop(uifigurehandle)
drawnow;
uifigurehandle.Visible = 'off';
uifigurehandle.Visible = 'on';
end
Run Code Online (Sandbox Code Playgroud)
其中,如果我们将其带入示例代码中:
% 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);
Run Code Online (Sandbox Code Playgroud)
您的图形现在呈现在屏幕的最顶部.