Skip to main content

Experiences with Swing

Posted by eitan on July 8, 2004 at 7:16 AM PDT

I've had the pleasure to work on a Swing application these recent months, and I'd like to share with you one of the main conclusions I've arrive at.

It did take me a little time to gain fluency with the APIs. After all Swing is a fairly large API (over 600 classes). On the other hand, once that fluency is gained, developing in swing works out all right.

Specifically one quickly realizes how powerful and flexible Swing can be. For example, I wanted to construct a hierarchical JComboBox and it didn't take much to actually make that happen. I was able to devise such a widget (which I called JComboTree) by combining a JButton, JPopupMenu, JMenuItem, with a TreeModel.

Second, there's no denying that the Swing developer community is a large and active one. Many developers subscribe to the forums, submit their questions, their problems; they contribute their code, their ideas. It's all good (think Bruce allmighty :-)).

One even goes as far as finding all kinds of third party additions to Swing that fill in the gaps: things that a business developer would need but doesn't find "out of the box," incorporated into the Swing API. Let me give you an example: to support my particular Swing application, you will find these third party libraries:

  1. additional (awesome) layout managers from
  2. a jar file that bridges the gap between rendering a hyperlink and actually launching it in a browser (
  3. skinlf, to give my app additional/alternative cool skins (an alternative is jgoodies)
  4. jcalendar (widget for picking dates, displaying a month view)

Furthermore, if you don't find the Swing tabpane API good enough for your needs, you'll discover that the netbeans team wrote their own separate tabpane API. You'll also discover little pieces of clever code in the forums to give the existing tabpane API a few more features (such as displaying an 'x' on each tab to allow a user to dismiss them, like one does in mozilla for example).

You'll also surely come across various articles that have been written over time that show you additional nify and useful widgets written by various developers. One example is a swing TreeTable, that merges a JTree with a JTable, to allow one to display multi-column rows where the first column is a tree that allows nodes to expand and collapse. Another example is Alan Hollub's calendar widget (employing the decorator pattern).

Now, take a moment to think about the amount of time and effort I've spent: discovering these add-ons, learning to use them, trying out a bunch of them and figuring out which ones worked for me and which did not; which are mature enough and which are not.

Then comes that point in time where you scratch your head and ask yourself: why are these features not incorporated over time into the Swing API? Why isn't the developer team in charge of maintaining and developing the Swing API doing this type of work? This is exactly what a good software library manager does: they're in contact with the community, they distill various enhancements and contributions from the community. They keep the best ones, or work on the promising ones and finally incorporate them back into the Swing API. That's in essence what Redhat does for Linux. That's what Eric Raymond talks about in his various open source essays: how to be a successful open source software manager.

[IMHO] Therein lies the problem. I don't want to guess because I have no clue and I'll admit it. But something tells me that there's a mismatch. The swing libraries are not exactly open source. I'm sure the Swing team wants nothing more than to make our lives easier. Something tells me that this crucial last step of incorporating contributions back into swing is failing because of legal restrictions.

Swing could be more than just "nice," more than just "ok" or "i can live with it." Swing could be the most awesome thing out there. If only through the magic of open source development. The community is already there. The code is waiting to be integrated. What do we need to do next??

I believe that the good people at Sun are actually a step ahead of me. A number of recent announcements indicate that things are moving in exactly the right direction: JDIC and JDNC have been released. I can tell from the community reaction that these new libraries are terrific. Issues such as the ability to easily launch a hyperlink in the user's preferred browser are being addressed. What's really awesome is that these libraries are released under the LGPL.

Related Topics >>