【问题标题】:Set focus to a uifigure window将焦点设置到 uifigure 窗口
【发布时间】:2017-05-31 00:05:52
【问题描述】:

焦点切换到其他图形后,如何将焦点设置为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 的时间。

【问题讨论】:

    标签: matlab matlab-app-designer


    【解决方案1】:

    这是 The 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);
    

    您的人物现在呈现在屏幕的最上方。

    【讨论】:

    • 但是没有办法将初始光标焦点设置在 uifigure 的元素上?例如,uieditfield
    • @BrianD 这也是可能的,看看this Q&A
    猜你喜欢
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多