Problems with a resize function callback

조회 수: 2 (최근 30일)
Julien
Julien 2012년 10월 5일
Hi,
I'm developing a programmed GUI (using the nice GUI toolbox layout available on file exchange). What I want to do is to define minimal length and minimal height of the GUI figure to automatically resize it to avoid displaying problems when the user resize the screen.
To do so, I defined the following resize function callback associated to the figure GUI (I use nested functions, so it is not a variable problem)
function myGUI
mainFig=figure('Position',[139 122 1204 675]);
set(mainFig,'ResizeFcn',@Resize_clbk);
min_length=1200;
min_heigth=600;
%[.....]
function Resize_clbk(hObject,Event)
actual_pos=get(hObject,'Position');
if actual_pos(3)<min_length
set(hObject,'Pos',[actual_pos(1:2) min_length actual_pos(4)]);
end
if actual_pos(4)<min_heigth
set(hObject,'Pos',[actual_pos(1:3) min_heigth]);
end
end
end
This function works nice when I resize the figure from both rigth and bottom borders of the window, but it doesn't works any time when I resize the window from the left or top border, or any corner.
Does anyone have a solution ?
Thank's in advance for your help ^^
  댓글 수: 2
per isakson
per isakson 2012년 10월 5일
With FEX contribution do you refer to?
Julien
Julien 2012년 10월 5일

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 10월 6일
편집: Jan 2012년 10월 6일
This problem is not related to the GUI layout toolbox, but to the resizing of all Matlab figures. I've tried a lot of different tricks without success. Only on the Java level defining a minimum size is reliable:
FigH = gcf; % [EDITED: This works under R2009a, but fails for 2011b]
drawnow;
jFrame = get(handle(FigH), 'JavaFrame');
jProx = jFrame.fFigureClient.getWindow();
jProx.setMinimumSize(java.awt.Dimension(200,200));
The drawnow is required in R2009a, otherwise the limitation feature is active.
A nicer solution is to manage the resizing manually: Set 'Resize' to 'off', a user-defined resize function is triggered by the WindowsButtonDownFcn, when the cursor is less than 5 pixels from the window border. Check, if the mouse is on the left or right side of the figure. If the left side has been selected, the mouse motion is applied to the origin of the figure only until the distance to the right side is above the wanted limit.
Drawbacks: 1. The cursor is only caught inside the inner position of the figure. 2. The implementation is neither trivial nor lean. I assume you want to use the GUI layout toolbox to avoid writing a lot of special codes for standard tasks.
[EDITED] This works for 2009a and R2011b (I cannot test it under R2012b):
FigH = gcf; drawnow;
jFrame = get(handle(FigH), 'JavaFrame');
jWindow = jFrame.fHG1Client.getWindow;
jWindow.setMinimumSize(java.awt.Dimension(200,200));
  • R2011b: The figure size is not reduced below the minimum size during mouse movement.
  • R2009a: During resizing the minimum size is not considered. After the mouse is released, the window width and height is set accordingly. This moves the right window side, when you drag the left side below the limit.
  댓글 수: 1
Jan
Jan 2012년 10월 9일
편집: Jan 2012년 10월 9일
Together with some parsing of inputs and compatible with Matlab 2007a to 2011b (perhaps 2012b, but this is not tested yet): FEX: LimitSizeFig.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Julien
Julien 2012년 10월 6일
Yes I use this toolbox to avoid defining all positions vector for all my components, I really dislike to do this ^^ But I prefer the freedom we have when we build programmatic GUI.
I have no knowledge about Java level, I've just tried your code inside the clbk function, and I've got this error code :
No appropriate method, property, or
field fFigureClient for class
com.mathworks.hg.peer.HG1FigurePeer.
Error in myGUI/Resize_clbk (line 13)
jProx =
jFrame.fFigureClient.getWindow();
Error while evaluating figure ResizeFcn
when I get the 'java frame' property value, it returns me this : com.mathworks.hg.peer.HG1FigurePeer
  댓글 수: 6
Jan
Jan 2012년 10월 6일
편집: Jan 2012년 10월 6일
See [EDITED] in my answer.
Julien
Julien 2012년 10월 7일
편집: Julien 2012년 10월 7일
Yeahhh it works for ML2012a too :) Thank's a lot for your help

댓글을 달려면 로그인하십시오.

카테고리

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