Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Setting A Minimum Figure Size

Subject: Setting A Minimum Figure Size

From: Andrew

Date: 9 Jul, 2010 12:38:04

Message: 1 of 2

Hello,

I am looking to create a figure which can be resized by the user. However, I want there to be a lower limit to this capability. I tried using a method similar to the one below and it seems to work a majority of the time. If the user is resizing from the bottom or from the right, the program quickly resets the figure to the minimum size allowed. The problem arises when the user tries to resize from the left or top. The figure appears to flash repeatedly throughout the resizing process. What I believe is happening is that the resize callback is being called several times while the user is dragging the edge of the figure rather than waiting for the process to be complete. This would not be an issue except that when the user is done resizing, the program does not always return the figure to the appropriate size. I can't seem to find any rhyme or reason as to when it resizes perfectly
and when it fails to do so. I was curious if anybody knew why this was occurring and a possible way to fix it. Thank you.

function figureResize
    figure('ResizeFcn',@setMinimum);
end

function setMinimum(hObject,~)
    p1 = getpixelposition(hObject);
    
    if p1(3) < 400
        set(hObject,'Position',[p1(1:2) 400 p1(4)]);
        
        movegui(hObject,'onscreen');
    end
    
    if p1(4) < 300
        set(hObject,'Position',[p1(1:3) 300]);
        
        movegui(hObject,'onscreen');
    end
end

Subject: Setting A Minimum Figure Size

From: David

Date: 20 Jan, 2012 18:00:10

Message: 2 of 2

A little late on the answer, but I had this issue just recently and found no good answer. The only way I have found to do this effectively is with a little java magic. I am not well versed in all of the java classes out there, so this is from a lot of guessing and checking, but this should get you an idea

fig = figure;
drawnow; % Must flush figure queue to get fully constructed JavaFrame object
jFig = get(handle(fig), 'JavaFrame');
jFig.fFigureClient.getWindow.setMinimumSize(...
        java.awt.Dimension(400 , 300));

Note that the JavaFrame property is due to be removed, so this may not work in future releases, but is working on my version of MATLAB (7.10.0.499 (R2010a))

"Andrew" wrote in message <i1757c$bnl$1@fred.mathworks.com>...
> Hello,
>
> I am looking to create a figure which can be resized by the user. However, I want there to be a lower limit to this capability. I tried using a method similar to the one below and it seems to work a majority of the time. If the user is resizing from the bottom or from the right, the program quickly resets the figure to the minimum size allowed. The problem arises when the user tries to resize from the left or top. The figure appears to flash repeatedly throughout the resizing process. What I believe is happening is that the resize callback is being called several times while the user is dragging the edge of the figure rather than waiting for the process to be complete. This would not be an issue except that when the user is done resizing, the program does not always return the figure to the appropriate size. I can't seem to find any rhyme or reason as to when it resizes
perfectly
> and when it fails to do so. I was curious if anybody knew why this was occurring and a possible way to fix it. Thank you.
>
> function figureResize
> figure('ResizeFcn',@setMinimum);
> end
>
> function setMinimum(hObject,~)
> p1 = getpixelposition(hObject);
>
> if p1(3) < 400
> set(hObject,'Position',[p1(1:2) 400 p1(4)]);
>
> movegui(hObject,'onscreen');
> end
>
> if p1(4) < 300
> set(hObject,'Position',[p1(1:3) 300]);
>
> movegui(hObject,'onscreen');
> end
> end

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us