File Exchange Pick of the Week

GUI Layout (Part 3) 1

Posted by Doug Hull,

This is Part 3 of 3 Pick of the Week entries on GUIs.

In Part 1 of the series, I talked about using ResizeFcn to create a GUI that resizes well. In Part 2, I introduced a nifty function that provided more control of specifying the positions of UI controls. Just recently, one of our fellow MathWorkers, Brian, who works in the UI Building Team, posted a nice utility, BorderLayout, that does what my ResizeFcn in this entry does. It is modeled after Java's BorderLayout and is quite flexible. It allows you to partition the GUI into regions, and by placing the uicontrols inside those regions, you can control the size of those components.

Here's how you would create a right panel (with fixed width), that contains a smaller panel at the bottom with fixed height. The remaining panels adjust appropriately to fill the space.

figH = figure;

% East panel has a fixed width of 100 pixels
panel1 = BorderLayout(figH, 0, 0, 100, 0);

% The South panel (within the East panel)
% has a fixed width of 80 pixels
panel2 = BorderLayout(panel1.East, 0, 80, 0, 0);

uicontrol(...
  'String'  , 'I''m fixed in size', ...
  'Units'   , 'Normalized'        , ...
  'Position', [0 0 1 1]           , ...
  'Parent'  , panel2.South        );

Brian also made this post to the MATLAB Desktop Blog.

Comments?

Tell us about other GUI building utility tools from the File Exchange that you found useful.

Written by Jiro Doke, Senior Applications Engineer, The MathWorks, Inc.


Get the MATLAB code

Published with MATLAB® 7.5

1 CommentsOldest to Newest

I was most dismayed when I saw that as of 2008/10/07 only 178 people had downloaded this package from the File Exchange. It has a simple and clear interface that would save tens of lines of code in manual resizeFcns.

My only thought for its lack of popularity is that it appears to only be used for programmatically developed GUIs and not those developed in GUIDE.

An expansion of this to be able to work with GUIDE would be most useful. I would expect you could use each uicontrol’s ‘userdata’ field to store the alignment properties and have a master resize function that can be set to the root Figure to align all controls as desired.

Rod

These postings are the author's and don't necessarily represent the opinions of MathWorks.