FormLayout
This class is the result of my frustration with making simple forms in Java Swing. Often times, a developer just needs labelled text fields in sequence, followed by a few buttons. Every layout manager built in Swing has problems with this simple problem:
- GridLayout wants to give all cells the same size.
- Combinations of BoxLayout can easily screw up alignment.
- SpringLayout works, but is WAY too complex.
External libraries (such as the otherwise excellent wares from JGoodies are a good solution, but are trying to be too many things imho (and hence are big).
I wanted a solution that:
- Makes it as easy as possible to do simple label/data forms with (optional) buttons along the bottom, right-justified.
- Is lightweight (preferably one file of source or one .class).
- Doesn't require weird semantics.
The solution is FormLayout available via anonymous subversion at http://schmong.org/source. It's a single-source-file LayoutManager that is an (almost) drop-in replacement for managers such as BoxLayout.
Usage
[...control creation...]
// The form panel
JPanel form = new JPanel();
FormLayout layout = new FormLayout(form);
form.setLayout(layout);
form.add("Name", name);
form.add("Address", address);
form.add("City/State/ZIP", csz);
form.add("Interests", interests);
form.add("Special Offers?", spam);
form.add(FormLayout.BUTTONAREA, cancel);
form.add(FormLayout.BUTTONAREA, save);
[...assign to JFrame, etc...]
This particular code yields a layout like this:

Download
.ZIP package: schmong-utils.zip
Anonymous SVN: http://schmong.org/source/schmong-utils
CalendarPopup
Again, a class brought about out of frustration. This is an extremely simple-to-use control that is a combination textbox (for direct data entry) and pop-up calendar. Looks like this:

You use it basically like a JTextArea, and can feed it either Date objects from java.util or java.sql (clever!)
Usage
[...control creation...]
// The form panel
JPanel panel = new JPanel();
panel.add(new JLabel("Pick a date:"));
panel.add(new CalendarPopup(d));
[...assign to JFrame, etc...]
See the Javadoc for details.
Download
.ZIP package: schmong-utils.zip
Anonymous SVN: http://schmong.org/source/schmong-utils