MATLAB ResizeFcn callback fails

1 回表示 (過去 30 日間)
Paul
Paul 2011 年 11 月 15 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by