File Exchange Pick of the Week

February 29th, 2008

GUI Layout (Part 3)

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

One Response to “GUI Layout (Part 3)”

  1. Rodney Thomson replied on :

    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

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

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