How do I make a figure full screen programmatically in MATLAB?
Afficher commentaires plus anciens
I would like to make my figure "full screen" without using the mouse to maximize the figure window.
Réponse acceptée
Plus de réponses (6)
Antonio Javier Barragán Piña
le 6 Juin 2016
set(gcf, 'Position', get(0, 'Screensize'));
3 commentaires
Walter Roberson
le 24 Juin 2016
In MS Windows and in OS-X, this does not make the window "full screen". Instead, it makes the window "all of the screen except for the title bar or bottom bar or dock". You need special methods to go full screen.
Chuck
le 18 Oct 2017
This one is actually way better than the one verified above. Great job, thanks!
Walter Roberson
le 16 Jan 2020
You would put it in the code at the point at which you want to force the figure to full screen.
If you want to do it for a GUIDE GUI then you can put it in the *OpenFcn callback code.
Dominik Mattioli
le 20 Juin 2019
Modifié(e) : Dominik Mattioli
le 20 Juin 2019
If you want to account for the taskbar (I found this in the comments of some other question):
fh = figure();
fh.WindowState = 'maximized';
2 commentaires
Dominik Mattioli
le 16 Jan 2020
Not sure what you mean without seeing any code. As long as you’re not reassigning the variable for the specific figure’s handle (fh) in your for loop, this solution should always work.
Steven Lord
le 16 Jan 2020
If you're creating many figure objects in a loop and want them all to be maximized, you could set that property at creation.
fh = figure('WindowState', 'maximized')
Most if not all settable properties of Handle Graphics objects can be set this way, though sometimes (mainly for properties that interact like Units and Position) you may need to be careful about your input argument ordering.
Bogdan Dzyubak
le 16 Août 2016
Modifié(e) : MathWorks Support Team
le 24 Juin 2021
The proposed methods are simple but make the figure "nearly" full screen which can cause you to close the maximized Matlab session instead of the figure.
For actual maximize you can use the following:
figure;
pause(0.00001);
frame_h = get(handle(gcf),'JavaFrame');
set(frame_h,'Maximized',1);
5 commentaires
Walter Roberson
le 5 Nov 2019
Yes, the JavaFrame property will definitely be removed in a future release. MATLAB is moving towards non-Java based graphics.
There was no true full-screen method offered in R2017a, other than the hack of using Java, or the hack of using Windows API (like Jan shows)
Rik
le 5 Nov 2019
The nice thing is that you can either use the JavaFrame method or setting the window state. That should cover every release. So the only thing you need is a try-catch block.
Steven Lord
le 20 Nov 2019
Rik, if you don't need to support releases earlier than release R2007a in your code you can check using verLessThan instead of using a try / catch block.
Steven Lord
le 26 Avr 2018
9 votes
Jan
le 26 Fév 2018
Under Windows you can use the API of the OS, see https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi :
FigH = figure;
WindowAPI(FigH, 'full'); % fill the current monitor
WindowAPI(FigH, 'work'); % fill the current monitor without taskbar, if there is one
No window border anymore, just the inner position.
DGM
le 31 Déc 2020
Similar to Jan's answer, it's possible to use system-level tools to maximize windows in Linux. That way, the behavior should be version-agnostic and will resize the window to the geometry that you'd expect if you just clicked the window maximize button manually.
In order to identify the window externally, simply give the figure window an unambiguous title. Then you can just use wmctrl to fetch the windowid and subsequently maximize the window.
windowname='AUTOPLOTTER';
set(myfigurehandle,'numbertitle','off','name',windowname)
pause(1) % wait for the window manager
system(sprintf('winid=$(wmctrl -lx | grep "%s" | cut -d \\ -f 1 | tail -n 1); wmctrl -ir "$winid" -b add,maximized_vert,maximized_horz',windowname))
5 commentaires
DGM
le 1 Jan 2021
I don't have any intentions of including this in any FEX submissions simply due to the limited portability. I would just be inviting complaints upon myself.
Rik
le 1 Jan 2021
You claim this code is version agnostic. What kind of complaints would you be inviting? I haven't had any complaints in my function (the function I linked). I might include your code in a future version, but it has fairly low priority, as releases without the Java frame will have the window state property. That means my function is guaranteed to work. Code like yours might be required for Octave.
DGM
le 3 Jan 2021
I said it should be (Matlab) version-agnostic. I've only used it on a handful of versions, and nothing particularly new, so I can't guarantee that. I kind of expect that's the default unspoken disclaimer for Matlab code, especially as graphics stuff evolves.
The primary issue is that it's not platform-agnostic. It's not going to work on Windows or if wmctrl isn't installed. That probably means that the majority of users can't use this simplified code out of the box, and I don't feel like relying on everyone to read the FEX description before they download it and get disappointed. If someone else is in a better position to use it as a special case alongside code suited for newer versions or other platforms, I'll leave it to them.
I didn't say it was ideal. It's probably slower than anything else. It's just what I use in my own scripts for generating documentation. I have a habit of using the bludgeon of tools like wmctrl to solve problems when other apps have no means to behave as I expect, so maybe I tend to overuse it out of mere familiarity.
Rik
le 3 Jan 2021
There are plenty of submissions that sound like they have implemented some revolutionary idea, all while simply setting the Position to the screensize. Looking at the comments in Jan's submission I don't see anyone complaining that it only works on Windows. As long as your description clearly states this requirement, I don't see why it doesn't deserve a FEX page. The chance that it will be found by prospective users here is much smaller.
Do you have a way of programatically checking if wmctrl is working as expected? If so, you could even implement a check (along with isunix&&~ismac) and issue an error. In my humble opinion you shouldn't worry about people who don't bother to read the first two lines of your description.
If I ever decide to implement this, I will put a link to this answer in the comments of the code. If you ever do decide to post this to the FEX I can credit the FEX entry instead.
Catégories
En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!