View License

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

» Watch video

Highlights from

5.0 | 6 ratings Rate this file 7 Downloads (last 30 days) File Size: 60.5 KB File ID: #22968 Version: 1.8



Jason (view profile)


13 Feb 2009 (Updated )

A MATLAB class which controls layout and resize of a figure/uipanel/uicontainer.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

layout.GridBagLayout is a MATLAB class which controls layout and resize of a figure/uipanel/uicontainer. This class helps the MATLAB GUI developer design complex Graphical User Interfaces without the need for calculations or complex code for performing initial layouts or writing resize functions.
To get this to work in 2007b/2008a you can simply replace the calls to ishghandle(h, 'figure') with strcmp(get(h, 'type'), 'figure').


This file inspired Ui Signal Builder2, Uisignalbuilder, and Grid Layout.

MATLAB release MATLAB 8.6 (R2015b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
29 Dec 2010 Dirk Engel

30 Dec 2009 Ryan Ollos

Author has done a great job of responding to suggestions and making improvements and minor bug fixes.

27 Aug 2009 Ashish Sadanandan

28 Apr 2009 Ryan Ollos

This code makes up for a major shortcoming of MATLAB, and has helped me write GUIs more quickly and more cleanly. Thank you for sharing this great piece of work!

16 Apr 2009 Laurent Vaylet

Laurent Vaylet (view profile)

WOW!! We finally get these nice Java layout features in MATLAB. Congratulations, it is a really useful, documented and illustrated piece of code. If a 6-star rating existed, you would surely get it :-)

09 Mar 2009 Yair Altman

Yair Altman (view profile)

Magnificent piece of work!

13 Feb 2009 1.1

Removed log files that were not relevant or useful.

24 Mar 2009 1.2

Update layout method to better handle Axes using the 'OuterPosition' property so that Insets are not always necessary. This will use MATLAB's built-in axes spacing management.

Recapture HTML.

28 Apr 2009 1.3

Fix typos and Axes positioning.

29 Apr 2009 1.4

Make Axes positioning dependent on the ActivePositionProperty. Thanks for the catch Ryan.

09 Oct 2009 1.6

Fix a bug with the use of UIPanel. Take into account the BorderWidth property when calculating the number of pixels available for the layout.

16 Dec 2009 1.7

Handle the user-defined Max < default Min case by not allowing the Minimum values to ever be greater than the corresponding Maximum values.

16 Feb 2016 1.8

Update for new MATLAB Graphics system. Fix bug when making the UI visible for the first time.

Contact us