Taking on GUI Builders with the Swing JavaBuilder
As the author of the Swing JavaBuilder library, I'd like to present to you a simple tutorial that explains what it can do for you and how it can maximize Swing development productivity.
Since coding Swing by hand is extremely cumbersome, most developers have to fallback on IDE-specific GUI builders, such as NetBeans's Matisse or Eclipse's WindowBuilder. Although those are fine solutions, all visual GUI builders suffer from a set of common drawbacks:
- they are IDE-specific. Once you start using Matisse or WindowBuilder, your chances of easily moving your code from one IDE to another are next to nill
- they often generate extremely unmaintainable code (especially if using GroupLayout like Matisse, which is basically impossible for humans to code by hand)
- they've often hard to maintain if major changes to a screen need to be made (I've had a few fights with Matisse on that one where it seemed easier to code a panel from scratch than rework an existing one).
The Swing JavaBuilder library aims to fix all of this (and then some) by allowing you to code the whole UI declaratively in a YAML file (a JSON superset made popular by Ruby on Rails that relies on whitespace indentation for hierarchical structures, somewhat like Python).
Besides drastically reducing the amount of code required to actually create your controls, the Swing JavaBuilder offers also an innovative layout management DSL that runs on top of MigLayout (the layout manager that has made all JDK layout manager obsolete basically), which is basically something like a GUI builder, but in pure text.
All of this is covered in detail in our PDF book, so if this tutorial is of interest to you, please refer to it for more in-depth explanations. Unlike many open source projects, the Swing JavaBuilder comes with detailed developer documentation. You're not supposed to wonder through a maze of disconnected Javadoc pages or Java source files to figure out how it works.
With that introduction let's move on and create a simple, typical business application for entering a person's data.
Unlike JavaFX with it streaming video and shiny buttons that go "ping!" when you press on them (like that machine in Monty Python's "The Meaning of Life"), the Swing JavaBuilder is aimed squarely at those boring business applications with dozens of fields, validation rules and long running save processes. In short, the type of applications that probably 95% of us write for a living day to day.
The only thing you need to start is download the 0.3.FINAL release of Swing JavaBuilder and the YAML editor plugin for Eclipse. In NetBeans, a YAML editor is part of the base install and in IDEA I believe it is part of the Ruby on Rails plugin.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)