FormLayout and GridBagLayout

I recently joined a project that has switched from GridBagLayout to JGoodies’ FormLayout as a standard.  I’m happy about about this decision, because I have been using FormLayout for over a year.  However, one of my fellow developers is very skeptical of FormLayout, believing that GridBagLayout can do anything we need to get done.  Additionally, he really doesn’t like using unsafe Strings to declare columns and row in the FormLayout constructors (i.e. new FormLayout(“4dlu, p:g, 2dlu, p:g, 4dlu”, “p, 4dlu, p, 2dlu, p, 2dlu, p, 4dlu, p”)).  I’m trying to convince him that FormLayout is a superior LayoutManager, making Swing GUI development more powerful and easier.  Am I barking up the wrong tree, or is there something more I can use in my argument?

Part of the problem in convincing him is the nature of our application.  It has a fixed width and a scrollpane for the height, so much of the complexity of a LayoutManager is lost; we don’t need to plan for resizing, changing resolution, or font.  We also have only one main pane, so keeping the layout stable from one panel to another is irrelevant.  Similarly, our customers tend not to care about making sure that columns have the same width without forcing the components to a set size making sure lines have the same height, and aligning font baselines.  So these advantages of FormLayout are lost.

FormLayout still takes a lot fewer lines of code than GridBagLayout does, but is that enough of an advantage by itself?  Is it worth using FormLayout if you have a fixed-size workspace?


About Lance Finney

Father of two boys, Java developer, Ethical Humanist, and world traveler (when I can sneak it in). Contributor to Grounded Parents.
This entry was posted in Programming. Bookmark the permalink.

3 Responses to FormLayout and GridBagLayout

  1. Adam Jordens says:

    Last year I led the migration in our application from using GridBagLayout to JGoodies FormLayout. I would have to say that its a worthwhile transition, even if it’s just for the fewer lines of code (and inherent simplicity) of FormLayout spec’s versus GridBagLayout spec’s. FormLayout panels are definately easier to maintain than their equivalents in GridBagLayout (but maybe your application is simple enough that this isn’t a primary concern).

    You can abstract the form layouts however you want so you don’t always have to use the String definitions if you always find yourself using a similar layout panel after panel. For us, we generally always use the provided FormBuilders so we don’t need to do too much esoteric stuff like statically defining the actual rows. I don’t know the details of your application, but I definately consider FormLayout to be a step up from GridBagLayout.

  2. Rob Abbe says:

    JGoodies software is ecellent. However, Gridbag just isn’t that hard to use and it doesn’t require an additional jar file. I do like the fact that the Form layout allows you to specify dialog units, but aside from that I see little upside. It’s pretty easy to get a drop off in the amount of code required when using gridbag, by writing routines to simplify it’s use.

    I think the thing gridbag lacks most is proper documentation and examples. Karsten did a great job documenting his Form layout.

  3. Frank Nimphius says:

    The tiny little thing I don’t like with default LayoutManagers, like GridBag, is that they require a Swing component to be placed on the panel before they visually start existing.

    JGoodies Forms allows you to first get clear of what the grid to hold your layout should look like, greatly reducing the lines of code to write for this. One way or another, you can create all layouts with any kind of LayoutManagers that are based on a grid.

    Dr. Heinz M. Kabutz, the publisher of “The Java Specialists’ Newsletter” once said…

    “If you want to age quickly, try and maintain some GridBagLayout code written by someone else … ”

    And right he is.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s