Bookmark and Share

Using SwingX 1.0 in NetBeans 6.7.1

The recent rise of JVM languages (for instance Clojure and Scala) has also been restoring the relevance of Swing. While there’s also SWT and Qt Jambi, Swing is still the workhorse choice for creating GUIs on the JVM. It’s good enough for most purposes and, unlike the rivals, requires no extra native libraries. Above all, it’s stable; it doesn’t need to change rapidly any more (which confuses some people to think that “Swing is dead”) because it already does what it’s supposed to do. The layout managers are all horrible, but you can always use an external one, like the magnificent MiGLayout. Swing has its issues, but overall it’s a decent cross-platform GUI toolkit with some unrivalled qualities.

Annoyingly, the core Swing’s component assortment is a bit incomplete. Luckily, it’s possible to extend it with custom components. There are several commercial and free extensions available. The most “official” of the free ones is SwingX, from which some components were incorporated into JDK 6, and presumably a couple of more of them (namely, JXLayer and JXDatePicker) will become standard in JDK 7. (Although, the current state of ex-Sun / Oracle / Java / Swing is confusing, to say the least. It seems that they’re dumping money into the saturated market of marginal web technologies at the cost of ignoring lots of their former core competence and pissing off voluntary developers. Let’s see how things advance.)

SwingX 1.0 was released in June 2009. I wanted to install it into NetBeans so that the components can be used as visual items in the Matisse editor. Even if the final GUI would be written by hand, I’ve found Matisse to be the best way to quickly prototype GUI ideas.

  1. Download SwingX 1.0 packages from the SwingX project site. For some reason the Binaries package seems to include the JavaDoc too. Sources are optional, take them if you want.

  2. Unzip the zips to swingx-1.0 and swingx-1.0-src directories under wherever you store your libraries.

  3. In NetBeans, go to the Library Manager (Tools → Libraries), click New Library…, name it SwingX, and add swingx-1.0\dist\swingx-1.0.jar and swingx-1.0\dist\swingx-beaninfo-1.0.jar to the Classpath tab, swingx-1.0-src\src directory to the Sources tab, and swingx-1.0\docs\javadoc directory to the Javadoc tab.

  4. Go to the Palette Manager (Tools → Palette → Swing/AWT Components), click New Category…, name it SwingX, click Add from Library…, and select the SwingX library that you created in step 3. Activate all the components (Ctrl-A), choose the SwingX category, and you’re done!

There are some issues — the components appear in the palette without icons, and additionally there are all kinds of “Painter” objects and other stuff that I believe is not supposed to be there. The Palette works, nevertheless, and you can get rid of the unrelevant items by deselecting them in the Palette Manager. If someone knows how to solve this elegantly, please let me know.

To use the SwingX components in a project, you need to add SwingX to your project’s libraries: right-click the Libraries node, select Add Library → Import… → SwingX → Import Library. Depending on your project’s settings this may take a few seconds, just wait patiently. Now you can use the components just like normal Swing components. Start with JXTaskPane, for instance.

The usage documentation of SwingX is poor and scattered, comprehensive reference tutorials are nonexistent, but don’t let the sad state of documentation and packaging fool you; the components themselves are quite usable. In addition to the JavaDocs, the best single tutorial I’ve found is the demo sources in the SwingX sources package.

Official SwingX sites
SwingX project main site.
SwingX Wiki.
SwingLabs discussion forum.

SwingX learning resources
Introduction to JXBusyLabel.
Introduction to JXTaskPane.
Introduction to the concept of Painters.
JXTable HowTo.
Searchable JXTreeTable example.
Using JXTable with Beans Binding in NetBeans.
Various SwingX examples (in French!). Translation here.
Introduction to JXDatePicker.
Introduction to JXPanel.
Introduction to JXTipOfTheDay.
Introduction to JXTable.
Introduction to JXStatusBar.
Introduction to JXHyperLink.
Last modified: 2009-10-22 21:06 +0300

blog comments powered by Disqus