View License

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

» Watch video

Highlights from

4.5 | 2 ratings Rate this file 3 Downloads (last 30 days) File Size: 12.5 KB File ID: #29472 Version: 1.5
image thumbnail




20 Nov 2010 (Updated )

An intuitive and flexible layout manager

| Watch this File

File Information

GridLayout was inspired by the GridBagLayout manager. It is equally flexible but more intuitive for my taste and it also requires less boilerplate code.

Each cell is a uicontainer and can hold only one child. Unlike GridBagLayout, children are added at creation time by passing the cell container handle as their parent. No 'Add' methods are needed, which reduces the amount of code.

Cell sizes can be specified in pixels or as relative values. Merging and removing cells are supported, as well as various alignment options: stretch, center, left, right, top, bottom.

The archive also includes demos illustrating the GridLayout capabilities . Bug reports and suggestion for improvement are very much appreciated. Download, unpack, and enjoy!


Grid Bag Layout inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
18 May 2012 Mihail Petrov

Eric, the Layout.Cell property itself is an array of uicontainers. This is one of the the main features of GridLayout. You don't need any additional function.

Comment only
17 May 2012 Eric Cousineau

To make it easier to wrap child objects, such as nested GridLayout's and plots, I think a function such as GridLayout.WrapCell(Row, Col) would help. It would create a uicontainer() inside the cell, and then return a handle to that container.

Comment only
28 Mar 2012 Mihail Petrov

Another change was to replace the HMargin and VMargin parameters with LMargin, RMargin, TMargin, and BMargin, that is, left, right, top, and bottom. This is very useful for axes in particular. See demo 7 for an example.

Comment only
27 Mar 2012 David

David (view profile)

Sounds awesome, can't wait to give it a try! Thanks Mihail!

Comment only
10 Oct 2011 Mihail Petrov

Hi David & Eric,

Give me a few days still and I'll upload the fixed version. I've been really busy these days...

Thanks for your feedback!

Comment only
08 Oct 2011 David

David (view profile)

Pretty cool library, thanks! I'm having problem #2 mentioned above by Eric Cousineau. Really needs to be able to handle multiple children in an axes object to be functional for plotting purposes.

08 Sep 2011 Eric Cousineau

Sure thing! I commented a small portion in the constructor to allow ~ishghandle() objects to contain a GridLayout.
I also updated the UpdateLayout() method to allow for plots.
I have uploaded a diff file:

However, I think it would probably be easier if both plots and child GridLayouts were wrapped in uicontainers() - that way they can be contained by a GridLayout. I was thinking that this wrapping could happen at the first call to UpdateLayout().

Comment only
17 Aug 2011 Mihail Petrov

Eric, thanks for the feedback and rating.

Could you indicate what exactly you changed in the code? In the past months I made several small changes myself and I'd like to merge them with yours before uploading a new version.

Comment only
15 Aug 2011 Eric Cousineau

Just realized a couple of things:
1) You can nest GridLayout's by disabling the check (ishghandle()) in the constructor and wrap it in a uicontainer.
2) If you add legends for your plot, it will introduce additional children into the cell, causing errors. The best fix for this is to wrap it in a container. This is also another bugfix towards adding plots without the little workaround.

15 Aug 2011 Eric Cousineau

This is an awesome redux of GridBagLayout!

I noticed that there was a bug when resizing plots. Found a bugfix in Jason's layout.GridBagLayout and incorporated it into GridLayout.ResizeCell().

I have uploaded the code to

Thank you again!

Comment only
22 Nov 2010 1.1

A few bugs were fixed and an additional demo added.

27 Mar 2012 1.4

Added support for:

1) axes with legends (as requested)

2) nested layouts (as requested)

3) automatic row/column sizing (experimental)

28 Mar 2012 1.5

Forgotten to add ParseArgs and GetArg functions to the release.

Contact us