Clear Filters
Clear Filters

MATLAB ResizeFcn callback fails

4 views (last 30 days)
Paul
Paul on 15 Nov 2011
I am editing a GUI written in MATLAB and have a line in the OpeningFcn that sets the callback for resizeing the figure.
set(hObject, 'UserData', handles.ParentFig, 'ResizeFcn',@cbFigResize, 'CloseRequestFcn', @Cancel);
The callback is pasted below with much edited out for simplicity.
function cbFigResize(src,evt)
% check if figure width is less than 600
if fpos(3) < 600
%set min. width to 600
fpos(3) = 600
end
%check if figure height is less than 560
if fpos(4) <560
% set minimum height to 560
fpos(4) = 560;
end
My coworker runs Windows XP and an earlier version of MATLAB. I run Windows 7 and MATLAB 7.12.0.635. Now when he resizes figures they always resize properly. When I run the same code I can sometimes get the figure smaller than the above set minimum width and height limits. My coworker says it is a Windows 7 interrupt problem. If anybody else out there has this problem he found a simple but illogical workaround which I will post below.
function cbFigResize(src,evt,doStop)
if nargin < 3
doStop = false;
end
% check if figure width is less than 600
if fpos(3) < 600
%set min. width to 600
fpos(3) = 600
end
%check if figure height is less than 560
if fpos(4) <560
% set minimum height to 560
fpos(4) = 560;
end
if ~doStop
cbFigResize(src,evt,true)
end
You can see that this function calls itself with a flag that stops if from becoming an infinite loop. And now I cannot resize windows below the minimum. Has anybody any insights into this behavior?

Accepted Answer

Jan
Jan on 15 Nov 2011
Edited: Jan on 26 Jul 2013
This is not a valid definition of the ResizeFcn:
'ResizeFcn',@ResizeFcn',@cbFigResize, ?!
You can use this to limit the figure size:
jFrame = get(handle(gcf), 'JavaFrame');
try
jProx = jFrame.fFigureClient.getWindow();
catch
jProx = jFrame.fHG1Client.getWindow();
end
jProx.setMinimumSize(java.awt.Dimension(600, 560));
  4 Comments
Kyungjoon Kim
Kyungjoon Kim on 23 Mar 2012
I received this error message..
No appropriate method, property, or field fFigureClient for class
com.mathworks.hg.peer.HG1FigurePeer.
and I found following script..
jFrame = get(handle(gcf), 'JavaFrame');
jProx = jFrame.fHG1Client.getWindow();
jProx.setMinimumSize(java.awt.Dimension(600, 560));
Jan
Jan on 23 Mar 2012
@Kyungjoon: Please post your Matlab and Java version.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!