Problems with a resize function callback

2 vues (au cours des 30 derniers jours)
Julien
Julien le 5 Oct 2012
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 commentaires
per isakson
per isakson le 5 Oct 2012
With FEX contribution do you refer to?
Julien
Julien le 5 Oct 2012

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 6 Oct 2012
Modifié(e) : Jan le 6 Oct 2012
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 commentaire
Jan
Jan le 9 Oct 2012
Modifié(e) : Jan le 9 Oct 2012
Together with some parsing of inputs and compatible with Matlab 2007a to 2011b (perhaps 2012b, but this is not tested yet): FEX: LimitSizeFig.

Connectez-vous pour commenter.

Plus de réponses (1)

Julien
Julien le 6 Oct 2012
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 commentaires
Jan
Jan le 6 Oct 2012
Modifié(e) : Jan le 6 Oct 2012
See [EDITED] in my answer.
Julien
Julien le 7 Oct 2012
Modifié(e) : Julien le 7 Oct 2012
Yeahhh it works for ML2012a too :) Thank's a lot for your help

Connectez-vous pour commenter.

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by