How can I make window to be fullscreen and resizable in Matlab GUI ?

117 visualizaciones (últimos 30 días)
Hi,
I have a question about matlab GUI. I'm programming an aplication only about one window and a have quite a lot buttons etc. So I would appreciate if I could made the gui window to be fullscreen. For example by default 1366 x 768 on normal fullscreen like in Windows. It would be great if it could be resizable just like in windows and if it would be smaller than all the buttons etc. sliders would show up...How can I do that in matlab GUI ? I have no clue...Where GUI even take data for resolution of the screen ?
Thanks, Peter

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 26 de Oct. de 2012
Are you using GUIDE with the Resizable set to off?
Go to: GUIDE->Tools->GUI Options->Resizable Behavior

Más respuestas (5)

Image Analyst
Image Analyst el 26 de Oct. de 2012
Editada: Image Analyst el 2 de Jun. de 2016
Here is the official Mathworks response: "There is no built-in functionality to maximize, minimize or get the state of a figure in MATLAB." See this link They used to recommend maxfig but don't anymore.
I usually do this:
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
though it just resizes the window and leaves it in the "normal" state, not truly maximized. Though the advantage of this is that it's still resizeable like you wanted. A truly maximized window is not resizeable.
I know there are some Java methods also. Go here for a comprehensive discussion: Undocumented MATLAB
Attached is the function I use, MaximizeFigureWindow, based on discussions with Yair Altman.
  3 comentarios
Image Analyst
Image Analyst el 13 de Jul. de 2019
referencing gcf should not bring up a new window. Attach your code so I can fix it.
noNickame
noNickame el 15 de Jul. de 2019
classdef MyGUI_Test < matlab.apps.AppBase
properties (Access = public)
UIFigure matlab.ui.Figure
TabGroup matlab.ui.container.TabGroup
%and many other ui-items
end
properties (Access = public)
%Just defining some variables - not important for maximizing window
end
methods (Access = private)
function startupFcn(app, w)
MaximizeFigureWindow();
%Setting some of the variables defined above
end
%Many other functions for push-butons etc.
end
methods (Access = public)
function app = MyGUI_Test(varargin)
createComponents(app)
registerApp(app,app.UIFigure)
runStartupFcn(app,@(app)startupFcn(app,varargin{:}))
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end
Due to the code is quite long and the most parts only concern creation of buttons etc. and defining what to happen, when tey are pushed or values are changed I left them out.
I guess the major information is, that I call the MaximizeFigureWindow - Function in the startupFcn. Is that wrong?
At least this was the only place, where Matlab App creator allows me to make changes beside in the item-functions.
Thanks in advance!

Iniciar sesión para comentar.


Jan
Jan el 26 de Oct. de 2012
Editada: Jan el 26 de Oct. de 2012
You can get the screen size by:
get(0, 'ScreenSize')
But creating a full screen window is not trivial in pure Matlab, but the WindowsAPI can help: FEX: WindowAPI.
In the Figure's ResizeFcn you can add code, which inserts sliders ( uicontrol('Style', 'slider') ). Some examples are published in the FileExchange.

Petr
Petr el 26 de Oct. de 2012
Wow thanks, now I at least know where to look...
but still I would appreciate if app would go to fullscreen right away and then if I got it smaller, than sliders would appear...Is that even possible ?
Thanks, Peter
  1 comentario
Image Analyst
Image Analyst el 26 de Oct. de 2012
Editada: Image Analyst el 26 de Oct. de 2012
I don't think it's possible to make a GUI that's larger than your screen. I haven't tested it on dual-screen extended desktops though so I don't know what would happen there. The code:
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
will work anywhere and work on the current figure. If you use that, or maxfig, with a GUIDE app, you might have to put it in the OutputFcn instead of the OpenFcn. This is because the GUI must already be displayed, which isn't necessarily the case with the OpenFcn. And, believe it or not, the OutputFcn gets executed both when launching your GUI and when shutting it down. Here's some code I have where I use maxfig with a GUIDE application:
% Call special function that The Mathworks gave me to maximize the window and leave it in focus.
% minfig(F,1) % minimizes the figure window for the figure with handle F
% minfig(F,0) % restores figure F if F is minimized
% maxfig(F,1) % maximizes the figure window for the figure with handle F
% maxfig(F,0) % restores figure F if F is maximized s = figstate(F) % returns the state of figure { Maximized | Minimized | Normal }
% Note: This works only if the window is already displayed. If not, it will throw a java exception.
maxfig(handles.figMainWindow, 1) % Maximizes the figure window for the figure with handle in the first argument.
By the way, this should have been a comment, not an Answer to your question.

Iniciar sesión para comentar.


Felipe Guerrero
Felipe Guerrero el 7 de Abr. de 2015
YOU HAVE TO PUT:
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
in the OutputFcn() in your GUI
;)

ewald strasser
ewald strasser el 2 de Oct. de 2018
Hi! I want to state the obivous for people like me.
Default settings of GUIDE can mess with your formatting. If you choose in GUIDE 'File-Export_to_Matlab-file' in the menu you have much greater controll of the formatting in the resulting m-file.
The example files show an example that comes directly from GUIDE (Beispiel) and one that is exported (Beispiel_export). The goal was to have a GUI in fullscreen that gives back the string of the button pressed, disable all buttons and enable them when calling the GUI function again. As you can see the GUIDE version uses different parameters for figure appearance. The exported version does not show this behavior by default and you can alter settings that are not allowed to be changed in the GUIDE version.
Greetings, Ewald

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by