简体   繁体   English

如何在启动时最大化MATLAB GUI图形/窗口?

[英]How to maximize a MATLAB GUI figure/window on startup?

I am currently evaluating GUIs in MATLAB and was wondering how to maximize a GUI window on startup, without the need for user interaction. 我目前正在评估MATLAB中的GUI,并且想知道如何在启动时最大化GUI窗口,而无需用户交互。 The function I am using is stated hereafter and works fine if called on a button press, but calling it in the figure's OpeningFcn won't help. 我正在使用的函数在下文中进行了说明,如果在按下按钮时调用它,则可以正常工作,但是在图形的OpeningFcn中调用它不会有帮助。

http://www.mathworks.com/matlabcentral/fileexchange/25471-maximize http://www.mathworks.com/matlabcentral/fileexchange/25471-maximize

Any help on some startup section to place the function call, which is executed after the GUI window has been drawn? 在绘制GUI窗口后执行的某个启动部分是否有任何帮助来放置函数调用? I searched for solutions related to startup code in MATLAB GUIs, but there were no results to date. 我在MATLAB GUI中搜索了与启动代码相关的解决方案,但迄今为止没有任何结果。 Thanks in advance for your efforts. 在此先感谢您的努力。

Since many people seem to be interested in this and there is still no public solution, I will describe my approach: 由于许多人似乎对此感兴趣,并且仍然没有公开的解决方案,因此我将介绍我的方法:

  1. In the YourGUIName_OpeningFcn(hObject, eventdata, handles, varargin) function, append the following lines: YourGUIName_OpeningFcn(hObject, eventdata, handles, varargin)函数中,添加以下行:

     % Initialize a timer, which executes its callback once after one second timer1 = timer('Period', 1, 'TasksToExecute', 1, ... 'ExecutionMode', 'fixedRate', ... 'StartDelay', 1); % Set the callback function and declare GUI handle as parameter timer1.TimerFcn = {@timer1_Callback, findobj('name', 'YourGUIName')}; timer1.StopFcn = @timer1_StopFcn; start(timer1); 
  2. Declare the timer1_Callback and timer1_StopFcn functions: 声明timer1_Callbacktimer1_StopFcn函数:

     %% timer1_Callback % --- Executes after each timer event of timer1. function timer1_Callback(obj, eventdata, handle) % Maximize the GUI window maximize(handle); %% timer1_StopFcn % --- Executes after timer stop event of timer1. function timer1_StopFcn(obj, eventdata) % Delete the timer object delete(obj); 
  3. Declare the maximize function: 声明maximize功能:

     function maximize(hFig) %MAXIMIZE: function which maximizes the figure withe the input handle % Through integrated Java functionality, the input figure gets maximized % depending on the current screen size. if nargin < 1 hFig = gcf; % default: current figure end drawnow % required to avoid Java errors jFig = get(handle(hFig), 'JavaFrame'); jFig.setMaximized(true); end 

Source of the maximize function: maximize功能的来源:

http://www.mathworks.com/matlabcentral/fileexchange/25471-maximize http://www.mathworks.com/matlabcentral/fileexchange/25471-maximize

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM