This post originated from an RSS feed registered with Java Buzz
by Simon Brown.
Original Post: Avoiding the GridBag ... reminds me of GridBagPanel
Feed Title: Simon Brown's weblog
Feed URL: http://www.simongbrown.com/blog/feed.xml?flavor=rss20&category=java
Feed Description: My thoughts on Java, software development and technology.
Scanning through JavaBlogs, I came across a blog entry from java.net entitled Avoiding the GridBag that talks about the packer project - a way to simplify the GridBag API. This reminded me of a cool little component that I created for a Swing project a few years ago.
If you've done any Swing programming, you'll know that building forms in Swing can be a tricky process, especially if you decide to use the infamous GridBag layout manager. To make this task easier, I created a GridBagPanel - essentially
a Swing JPanel that has GridBag set as its layout manager. GridBagPanel provides a very simple API that can be used to build forms (like the one shown below) very easily.
The following code sample shows how simple it is to build a form like this.
// create the components as usual
JTextField toTextField = new JTextField();
JTextField ccTextField = new JTextField();
JTextField subjectTextField = new JTextField();
JTextArea messageTextArea = new JTextArea(4, 32);
// then build a GridBagPanel, 4 rows by 2 columns
GridBagPanel p = new GridBagPanel(4, 2);
// and finally add rows specifying the label and the component
p.addRow("To", toTextField);
p.addRow("CC", ccTextField);
p.addRow("Subject", subjectTextField);
p.addRow("Message", new JScrollPane(messageTextArea));
I had completely forgotten about that until the packer project came up, so perhaps I should dig out the source code and make it availble under an open source license. Anybody think there's a demand for this sort of stuff? I also have a whole framework for building standardised dialogs and panels that conform to the Java Look and Feel guidelines if I can find it! I have the slides from a BOF that I gave at JavaOne 2000 about this stuff and I'm sure I have the code somewhere.