Jean-Francois has posted 2 posts at DZone. View Full User Profile

DesignGridLayout 1.1: Now With Multiple Row-Span Support

02.18.2009
| 4154 views |
  • submit to reddit

DesignGridLayout 1.1, the easy but powerful open source Swing LayoutManager, has just been released.

You can try DesignGridLayout examples online immediately.

Version 1.1 brings the following features in comparison to 1.0:

  • support for components spanning multiple rows through an ultra simple API
  • optimized the size of the example jar (removed all screenshots that are used during automatic tests)
  • completely refactored the examples application
  • added an option to disable "smart vertical resize" feature

Support for components spanning multiple rows is the main improvement in this version, you can see an usage example following:

JList list = new JList();
// Further list initialization here...
DesignGridLayout layout = new DesignGridLayout(panel);
layout.row().grid(new JLabel("lbl11")).add(new JTextField("field11")).grid(new JLabel("lbl12")).add(list);
layout.row().grid(new JLabel("lbl21")).add(new JTextField("field21")).grid().spanRow();
which gives the following result (with default Look & Feel):

Example of a list spanning 2 rows


In addition, the following bugs have been fixed:

  • fixed several problems with baseline alignment (only on Java 5)
  • fixed a problem with smart vertical resize of JList
  • fixed an exception with multi-grid feature
  • fixed an exception when creating a row but adding no component to it
  • fixed a bad look with grids having just a label but no component

 

What is DesignGridLayout?

DesignGridLayout is a revolutionary and innovative Swing LayoutManager inspired by the use of canonical grids for user interface design.

DesignGridLayout's primary innovation is a well behaved simple layout algorithm exposed as a convenient API. Just add rows from top to bottom and components from left to right.

DesignGridLayout is also a smart Swing LayoutManager:

  • it manages all margins, gaps, alignments (baseline and vertical) automagically for you, while respecting UI guidelines for the current platform (as defined by the Look and Feel)
  • it makes sure your UI is always visually pleasing (that's the power of canonical grids)
  • it knows how to count: you never need to specify upfront how many columns or rows you have in your UI, DesignGridLayout will automatically count that for you! This way, you generally don't need to mock up your UI on paper first and try to draw virtual grid lines like most grid-oriented LayoutManagers impose
  • it does not require you to specify which rows should be able to vertically grow during user resize and which rows should have fixed height: DesignGridLayout automatically detect which rows should vary in height!
  • DesignGridLayout will also make sure that the height of components such as a JList is always appropriate for the content, i.e. allows to display all rows in their full height (not truncated like all other LayoutManagers)
  • thanks to its fluent API, DesignGridLayout makes it a breeze to define your UI forms; it also makes the learning curve very short: you can be fully effective in less than one hour!

 

DesignGridLayout API is so intuitive that you can master it in just a couple of hours. After just one hour, you are able to build your forms and dialogs in no time:

  1. Write the layout code the way the layout should appear
  2. Run the code
  3. It just works!

 

With DesignGridLayout, there is no need for a long "code, try and repeat" process. No need to fine-tune the layout code with hard-coded dimensions either, canonical grids just ensure that components are sized correctly!

What's coming next for DesignGridLayout?

This post in DesignGridLayout author's blog gives some information about the roadmap for the next version of DesignGridLayout.

0
Published at DZone with permission of its author, Jean-Francois Poilpret.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)