View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Limit figure size

4.0 | 1 rating Rate this file 8 Downloads (last 30 days) File Size: 3.53 KB File ID: #38527 Version: 1.1

Limit figure size


Jan Simon (view profile)


08 Oct 2012 (Updated )

Set minimal or maximal size of a figure

| Watch this File

File Information

LimitSizeFig - Set minimum and maximum figure size
Some dialogs become ugly, if their size is getting too small. Setting a minimal size in the figure's ResizeFcn leads to strange effects, when the left side of the figure is dragged. This function calls Java to limit the figure size.
LimitSizeFig(FigH, Prop, Ext)
  FigH: Handle of a Matlab figure.
  Prop: String, command:
        'min', 'max': Set minimum or maximum extent.
        'get': Reply the limits.
        'clear': Clear both limits.
  Ext: Extent as [1 x 2] vector, minimal width and height in pixels.
  FigH = figure;
  LimitSizeFig(FigH, 'min', [200, 200])
  LimitSizeFig('max', [400, 400]) % Uses GCF
  Limit = LimitSizeFig(FigH, 'get')

Tested: Matlab 7.7, 7.8, 7.13, 8.6, HG2, WinXP/32, Win7/64
Run the unit-test uTest_LimitSizeFig to check the validity on your Matlab version.

MATLAB release MATLAB 8.6 (R2015b)
MATLAB Search Path
Other requirements Does not work under Matlab 6.5
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
31 Jul 2015 Jan Simon

Jan Simon (view profile)

The method does not work in 2011b. The min and max figure sizes are set and stored in the jFrame.fHG1Client.getWindow object, but they do not affect the position. In R2009a everything was fine.

I'm not sure how this method can be supported reliably, because I do not have all Matlab versions.

Comment only
17 Oct 2014 Dan

Dan (view profile)

Thanks for the script it has been very useful for me.

It seems, there is a small compability issue with 2014b and the new graphics system (HG2). To access the java frame correctly, after line 99 of your code you need to add another catch for HG2:
jClient = jFrame.fHG2Client;
(see here

Comment only
17 Oct 2014 Dan

Dan (view profile)

16 Feb 2014 Jan Simon

Jan Simon (view profile)

Stephane: Thanks for your comment. I do not have R2013a to test or fix this.
Please feel free to send me suggestions for simplifications to the email address taken from the code.

Comment only
31 Jan 2014 Stephane

Thanks this is nice job ... unfortunatly setting max size does not work (R2013a). As a test you can try:

h = figure();
LimitSizeFig(h, 'min', [100 100]);
LimitSizeFig(h, 'max', [200 200]);

You will see that min size is ok, but that figure can still grow by any amount ;(

NB1: It's seems to be a bug in swing for 'setMaximumSize'.

NB2: I have refactored your code here to be simpler to use:

Comment only
20 Dec 2015 1.1

Adjutsed to R2015b

29 Feb 2016 1.1

Mentioned compatibility with HG2.

Contact us