post on the JPreference API of JFace sums up pretty well why SWT/JFace has
been gaining so much momentum these past years to create Java user interfaces.
I have been using AWT (and later, Swing) since the very first days, and while
I was fascinated by the idea of creating rich interfaces with my language of
choice, it was hard to ignore their shortcoming.
First of all, performance took a long time to become acceptable, and even now
when we have finally reached this point, the bottom line is still that it takes
an awful lot of efforts and expertise to produce an interface in Swing that
looks professional and feels native enough.
There are several reasons for this:
- The MVC model of Swing is a failure. It’s clever,
reasonably-well designed, makes a few needed compromises with the original
MVC idea, but it’s simply not used. Maybe it’s a matter of education
or lack of expertise from the developers, but I hardly see any code that
actually adapts the widget models to their own domain objects. Most of
the code I have seen is a set of helper methods converting DAO’s to the
original models, defeating the separation of view and model.
- Swing is built on AWT, which was not designed to be extended.
Throughout the years, AWT has been retrofitted and patched to support
various Swing requirements (does anyone remember the lightweight/heavyweight
debate that took years to settle?) but at the end of the day, the pyramid
feels cumbersome and shows very little advantages for developers.
- GridBagLayout is an absolute disaster and the perfect example
of something that is completely flawed and violates with a stunning
regularity the principle of least surprise. Whatever layout you are
trying to write, I am betting that you never reached it before a
discouraging number of trials errors (I strongly recommend checking out
JGoodies if you want some quality piece of
Swing software, and I’ll also take this advantage to give a quick shout out
to Romain Guy, who has been proposing a lot of very creative Swing ideas on
- Despite its ambition and purpose, Swing is still lacking "real-world"
widgets that would truly save developers valuable time. The
Preferences API above is just an example, but here is another:
wizards. How come Swing doesn’t have any? I have written several
Wizard classes already, and I’m sure I’m not the only one. No wonder
Swing applications still feel clunky and inconsistent. Another example
is the complete lack of integration with native operating systems (e.g. the
system tray in Windows). Sun is finally trying to fix this problem
with JDIC, and it’s about time. And it’s also way too late in my
opinion (maybe we’ll get it in Mustang).
SWT/JFace addresses all of these
Granted, part of it comes from hindsight and learning from Swing’s mistakes,
but I have to admit my very profound respect for the OTI team, which created an
amazing UI framework (of course, Eclipse and the RCP should be added to their
credit as well).
SWT/JFace is really the API that doesn’t get in the way of the developer and
that lets you achieve amazing results in record time.
Are there any drawbacks to SWT/JFace?
- It is not part of the JDK, so you need an additional download.
- Its non-Windows ports have been criticized for not being of the same
quality as it is on Windows (this is something that has vastly improved
these past months).
You basically have three options for your next GUI application: SWT,
SWT+JFace or RCP. I have no doubt that at least one of these options will
be the perfect match for your work, so be sure to evaluate each carefully before
making a decision.