MATLAB ResizeFcn callback fails

4 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2011-11-15
编辑:Jan 2013-7-26
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 个评论
Kyungjoon Kim
Kyungjoon Kim 2012-3-23
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 2012-3-23
@Kyungjoon: Please post your Matlab and Java version.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by