Comments on: Minimize/maximize figure window https://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window Charting Matlab's unsupported hidden underbelly Thu, 02 May 2024 08:00:01 +0000 hourly 1 https://wordpress.org/?v=4.4.1 By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-403774 Mon, 27 Mar 2017 08:40:53 +0000 https://undocumentedmatlab.com/?p=2310#comment-403774 @Richard – https://undocumentedmatlab.com/blog/hg2-update#observations

]]>
By: Richard B Hodgeshttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-403756 Mon, 27 Mar 2017 01:34:20 +0000 https://undocumentedmatlab.com/?p=2310#comment-403756 In 2017a, jFrameProxy = jFrame.fFigureClient.getWindow() gives an error:

Undefined function or variable ‘fFigureClient’

Is there any replacement for functionality?

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-391130 Thu, 20 Oct 2016 16:25:29 +0000 https://undocumentedmatlab.com/?p=2310#comment-391130 @Stijn – try adding pause(0.5) after the drawnow. If it works then you can play with the pause duration to find the minimal duration value that works well on your specific system.

]]>
By: Stijn Helsenhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-391097 Thu, 20 Oct 2016 06:47:55 +0000 https://undocumentedmatlab.com/?p=2310#comment-391097 I wanted to use the maximize function to get the size of the screen on which a figure is shown (using multiple screens). And “manually” (step by step) this works, but in a function, this doesn’t! In debugging mode, executing it, it works too.

jFrame = get(handle(figs(1)),'JavaFrame');
jFrame.setMaximized(true)
% nothing that I tried helps (drawnow, ...)
pos0 = get(figs(1),'Position');

When I first saw this, I thought: “simple: just add drawnow”, but that didn’t help.
Any idea?

]]>
By: Image Analysthttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-335570 Wed, 29 Oct 2014 20:49:01 +0000 https://undocumentedmatlab.com/?p=2310#comment-335570 Thanks. I didn’t know what that resize stuff was – I just had it in there because other code above did, and I thought I needed it. I just removed that line and now everything works great. Thanks for figuring it out for me!

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-335556 Wed, 29 Oct 2014 17:51:45 +0000 https://undocumentedmatlab.com/?p=2310#comment-335556 @IA – I’m afraid that this is the behavior for figure windows that have Resize=’off’. If you set Resize=’on’ (the default value), then it will work as you expect vis-a-vis the taskbar. If you wish to get the Resize=’on’ behavior while still disabling resizing you can use the following code snippet:

jFrame = get(handle(gcf),'JavaFrame');  % Resize='on'
drawnow; pause(0.1);
try
    jClient = jFrame.fHG1Client;  % HG1
catch
    jClient = jFrame.fHG2Client;  % HG2
end
jClient.setMaximized(true);
jWindow = jClient.getWindow;
maxSize = jWindow.getSize;
jWindow.setMinimumSize(maxSize);
jWindow.setMaximumSize(maxSize);
jWindow.setLocation(java.awt.Point(0,0));

It’s not perfect, but close enough…

]]>
By: ImageAnalysthttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-335553 Wed, 29 Oct 2014 17:31:42 +0000 https://undocumentedmatlab.com/?p=2310#comment-335553 Yair, it works now. Just one little problem. It’s SO maximized that it covers up the Windows 7 task bar at the bottom of my screen. Is there any way to have it maximized but still have the taskbar show up? That’s the way maximizing normally works.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-334455 Sat, 18 Oct 2014 15:53:12 +0000 https://undocumentedmatlab.com/?p=2310#comment-334455 @IA – Probably because the figure window is not fully rendered when the jFrame code is reached. This is due to the fact that in R2014b, the figure function no longer blocks execution until the figure is fully rendered.

I suggest moving the drawnow; pause(0.1); code to before the jFrame code, rather than after it – this will ensure that the figure is fully rendered at that time:

% Enlarge figure to full screen.
jFrame = get(handle(gcf),'JavaFrame');
set(gcf,'Resize','off');
drawnow; pause(0.1);
try
    jFrame.fHG1Client.setMaximized(true);  % HG1
catch
    jFrame.fHG2Client.setMaximized(true);  % HG2
end
]]>
By: ImageAnalysthttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-334380 Fri, 17 Oct 2014 16:34:10 +0000 https://undocumentedmatlab.com/?p=2310#comment-334380 Here’s my code:

% Enlarge figure to full screen.
jFrame = get(handle(gcf),'JavaFrame');
set(gcf,'Resize','off');
try
    jFrame.fHG1Client.setMaximized(true);  % HG1
catch
    jFrame.fHG2Client.setMaximized(true);  % HG2
end
drawnow; 
pause(0.1);

If I just let this run in R2014b (HG2) it throws an exception:

Error using test (line 60)
Java exception occurred:
java.lang.NullPointerException
	at com.mathworks.hg.peer.FigureFrameProxy.setMaximized(FigureFrameProxy.java:302)
	at com.mathworks.hg.peer.FigureMediator.setMaximized(FigureMediator.java:468)

and does not maximize the figure. HOWEVER, if I put a breakpoint anywhere in the try/catch, and it stops there, and I hit F5 to continue, it works just fine with no exception at all being thrown, just an orange warning:

Warning: figure JavaFrame property will be obsoleted in a future release. For more information see the JavaFrame resource on the MathWorks web site. 
> In test at 55

Why does it work only if there is a breakpoint stopped at and not when I just run it non-stop like I’d want?

]]>
By: Luis Vieira da Silvahttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-333751 Fri, 10 Oct 2014 06:39:53 +0000 https://undocumentedmatlab.com/?p=2310#comment-333751 Thank you for your help, Yair.

Indeed, that was obvious…

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-333746 Fri, 10 Oct 2014 05:51:23 +0000 https://undocumentedmatlab.com/?p=2310#comment-333746 @Luis – of course it does! what else did you expect? you created the figure with an initial size (Position) of 100×100 pixels, so when you de-maximize the figure it goes back to this size. Instead, create your initial figure with a larger size.

]]>
By: Luis Vieira da Silvahttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-333680 Thu, 09 Oct 2014 14:05:59 +0000 https://undocumentedmatlab.com/?p=2310#comment-333680 Hi,

I have one last issue with the use of this programming technique. Here is my code:

hfig=figure(...
  'Name','Topas',...
  'NumberTitle','off', ...
  'Resize','off',...
  'Units','pixels',...
  'Position',[0 0 100 100],...
  'PaperPosition',[0 0 24 16],...
  'PaperSize',[24 16],...
  'tag','main_fig',...
  'Menubar','none',...   % défini par la suite
  'Toolbar','none');     % défini par la suite
 
drawnow;pause(0.1);
jFrame = get(handle(hfig),'JavaFrame');
try
    jFrame.fHG1Client.setMaximized(true);  % HG1
catch
    jFrame.fHG2Client.setMaximized(true);  % HG2
end
drawnow; pause(0.1)

It works fine until I double-click on the title bar (I am running Matlab R2014a on Windows 7 sp1). Then the window of my application shrinks to a small square (about 100×100 pixels) and there is no way I can maximize it again.

Thanks in advance for your help
Luis

]]>
By: Luis Vieira da Silvahttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-330326 Thu, 28 Aug 2014 10:08:55 +0000 https://undocumentedmatlab.com/?p=2310#comment-330326 Thanks a lot, Yair, it works fine

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-330301 Wed, 27 Aug 2014 21:42:10 +0000 https://undocumentedmatlab.com/?p=2310#comment-330301 @Luis – simply switch the order of the actions:

set(hfig,'Resize','off');
try
   jFrame.fHG1Client.setMaximized(true);  % HG1
catch
   jFrame.fHG2Client.setMaximized(true);  % HG2
end
drawnow; pause(0.1);
]]>
By: Luis Vieira da Silvahttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-330292 Wed, 27 Aug 2014 17:25:53 +0000 https://undocumentedmatlab.com/?p=2310#comment-330292 Hi,

On figure creation, I would like to maximize it (easily done with your method) and then prevents users to change its size. To do so I use documented Matlab function ( set(hfig,’Resize’,’off’) ). There seems to have a side-effect: figure is slightly maximized. That means inner borders of the window are at the limits of the screensize and the not outer borders.. Why ?

my code:

hfig=figure(...
  'Name','Topas' ,...
  'NumberTitle','off', ...
  'Resize','on',...
  'Units','pixels',...
  'Position',pos_fen,...
  'tag','main_fig',...
  'Menubar','none',...
  'Toolbar','none');
drawnow;pause(0.1);
jFrame = get(hfig,'JavaFrame');
jFrame.setMaximized(true); 
drawnow;pause(0.1);
set(hfig,'Resize','off')

Thanks in advance

]]>
By: dubbel jhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-320604 Thu, 27 Mar 2014 15:57:00 +0000 https://undocumentedmatlab.com/?p=2310#comment-320604 Thanks, yours works.

and figured out what my fault was:

 fig = get((a(n)),'JavaFrame');

instead off:

 fig = get(figure(a(n)),'JavaFrame');

so now both methods work :)

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-320600 Thu, 27 Mar 2014 14:59:13 +0000 https://undocumentedmatlab.com/?p=2310#comment-320600 @Dubbel – it should work, assuming all your figures are in fact visible. I would wrap the internals of the loop in a try-catch, so that if one figures fails to minimize, the others will still work. Something like this:

allFigs = findall(0,'type','figure');
for figIdx = 1 : numel(allFigs)
    try set(get(handle(allFigs(figIdx)),'JavaFrame'), 'minimized',true); catch, end
end
]]>
By: dubbel jhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-320596 Thu, 27 Mar 2014 14:29:10 +0000 https://undocumentedmatlab.com/?p=2310#comment-320596 Hi there,

I tried to loop minimizing multiple figures with this ‘JavaFrame’ property.
I works fine for minimizing the matlab desktop, the current figure and for a specific figure. But till now i cant loop these commands.

So is there a reason why this code does not work?

% minimize all other figures (if any)
a = get(0,'children');    % is this the proper way to get the figures ???
for n = 1: numel(a);
    fig = get(figure(a(n)),'JavaFrame');
    set(fig,'minimized',1);
end

The idea is that when i start a certain GUI, all other Matlab windows will be minimized.

Other options i have in mind:
1. resize all figures and put them to an edge of the screen
% but this is not what i want

2. trying to ‘auto-click’ the ‘show desktop’ button in windows 7
Then i just automatically minimize all, and then start my gui window. This would be my best case scenario.

btw, nice site, learned a lot about matlab here.

]]>
By: Yair Altmanhttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-319832 Fri, 21 Mar 2014 00:45:00 +0000 https://undocumentedmatlab.com/?p=2310#comment-319832 @Terence – you cannot undecorate a Java Frame (figure window) using Java code after the JFrame is made visible, and you cannot access the JFrame in Matlab before it is made visible. In practice this means that you [probably] cannot do that with Java.

However, you may possibly be able to do it using Windows API if you’re running Windows. For this you can try using Jan Simon’s WindowAPI utility.

]]>
By: Terencehttps://undocumentedmatlab.com/blog_old/minimize-maximize-figure-window#comment-319825 Thu, 20 Mar 2014 23:57:36 +0000 https://undocumentedmatlab.com/?p=2310#comment-319825 Any ideas on how to remove the Title Bar from the figure window? I’ve tried frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setUndecorated(true); but get the error “Undefined variable “JFrame” or function “JFrame.MAXIMIZED_BOTH”.”

]]>