Java: FormatPanel

Warning: This is a beta version, and there may be changes. I use it myself on a number of projects, so it is not untested.

Known Bugs

Missing features

Try it

You can try a Java Web Start version of the FormatWordbencb. This will load a Java program onto your machine, but it has security permisssions to read or write your files, or do anything else dangerous. It will remain cached on your machine so that you can run it offline if you wish. Every time you run it a check will be made to see if there are updates, so it is always current. FormatWorkbench

Background

Advantages

Format driven
The general idea is to specify a format string (eg, "'Name' $ / 'Phone' $") and an array of components (Java 5 allows variable length parameters list). If you're familiar with printf() or other format-driven styles of programming, you should be comfortable with FormatPanel. Generally laying out all elements takes only two or three lines of code!
Grid with variable size rows and columns. Expandable.
This is similar in concept to GridBagLayout or an HTML table. Rows and columns are numbered from one and don't count borders and gaps (see below). The row and column sizes are computed as the largest of the preferred sizes of all components in that row or column. Expandable (eg, window is resized) cells are specified with x (horizontally expandable, or y (vertically expandable).
Multicell areas and alignment
A component can span more than one cell in the grid. Components fill their entire area by default, but may take their preferred size and be centered or aligned to a single or any two edges.
Borders and Gaps
Sun's Human Interface Guidelines give some guidance on layout. GridBagLayout, however, knows nothing about these guidelines, specifically giving no special help with borders and gaps. Format panel defaults to a standard border size (11 or 12 pixels) with 5-pixel gaps between rows and columns.
Massive reduction in layout code
I would say it roughly reduces the number of lines of layout code by about 50.
Labels and separators
Labels (single quoted strings) and line separators (format characters | and _) can be specified in the format, thereby reducing the number of contentless components that need to be created.

Example

// Create components first.
JTextField fnField = new JTextField(15);
JTextField lnField = new JTextField(15);
...
FormatPanel content = new FormatPanel(
              "'First Name' $x / 'Last Name' $"
              , new Component[] {fnField, lnField});

Basic Concepts

The format codes fall into the following groups.

Movement codes

Explicit movement (/ , \)

Component codes

Component specification. ($ '...' F - |) Followed by optional constraints. By default inserts components in next free position in the current row.

Constraint codes (w h N S E W x y)

Constraint codes must follow a component specification.

Gaps

Gaps are specified by a direction (N S E W), followed by an optional size in pixels, and an optional x or y expansion.

Border specification (B)

Gap unit size specification (G)