
RIP Swing, hello ....?
It's sad to see Swing fade away, but technology marches on and sometimes it's better to ditch 'legacy' tech in favor of new approaches. We still need a truly cross-platform UI toolkit, but what would that be today?
I've been meaning to get this post out for a while...
A few months ago I set out to build a cross-platform app to serve as a library/index of all the various video content (movies, TV shows, soccer games, etc) we have on our home network. Our home theater PC (HTPC) is Linux-based, but the desktops & laptops (yes, there are quite a few) in the house are running either Mac OS X or Windows XP. I was leaning towards using Java to satisfy the cross-platform requirement. Most of my Java experience was web-based, so I thought this would give me the opportunity to catch up with Swing (not to mention also try some of the uber-cool tricks documented in Swing Hacks).
Swing has been a much-maligned technology over the years, suffering, IMHO, from close association with Java applets. It has been steadily improved and enhanced with 'native' look and feel features. Swing apps on the Mac, for example, can easily look and behave like native apps. Some of the newer improvements I wanted to try out included:
- JavaFX. JavaFX 1.1 was about to come out so I spent some time digging into it...only to find that JavaFX is not yet cross-platform - only Windows and Mac are supported as of this post. The need to support my Linux HTPC was a showstopper for JavaFX.
- GroupLayout layout manager. One of the big issues with Swing has been tooling and layout. Swing apps depend on layout managers to arrange components in the UI, and the available layout managers didn't typically support the easy 'drag and drop' UI construction of tools like Visual Studio. This changed a couple of years ago when NetBeans included a fantastic Swing UI designer (Matisse) and it's supporting layout manager (GroupLayout) that finally put Java UI 'drag and drop' on a par with Visual Studio. The showstopper for this, for me at least, was that I would have to ditch IntelliJ and use NetBeans as my IDE! After playing with switching back and forth between IDE's I finally settled on using IntelliJ with it's JGoodies FormLayout layout manager. GroupLayout should be a stand Java library, so that all tools can support it (not just NetBeans).
- JSR 295 Beans Binding. Databinding is not a native concept in Swing. Swing does support a strict MVC approach, but each component type (List, TreeView, etc) has it's own custom model type that must be populated from your 'real' model objects. Digging into JSR 295 revealed that it was orphaned in favor of JavaFX, and the reference implementation has significant issues due to lack of true properties and events in the Java language (http://www.devx.com/Java/Article/39964/0/page/3).
- SwingX components. These are extensions to the core Swing toolkit, implemented by Swing Labs. In digging into this it became clear that Sun has effectively shut down the Swing Labs team, in favor of JavaFX implementation, meaning the components will likely not be maintained or implemented in the core Java distribution. Yikes! I decided to stick with the core Swing components.
I think I often take too much of a big picture view. I could have used a lot of this stuff anyway on such a small app, without major consequences. I guess my desire to try out 'current' Java UI tech was a real goal that I wasn't able to fulfill, leaving me with my app done, but not a sense of where the state of Java UI tech is at. Sun's lack of investment/support for Swing at the moment makes it clear that Swing is not the future of the Java UI. JavaFX may be the future, but it breaks the Java cross-platform promise as long as they don't support Linux.
As for the app itself, it's up and running on our home network and works well on Windows, Linux and Mac. It's not a very polished user experience at this point (you can see just how rough over at http://code.google.com/p/videobrain/), but it is functional. I just wished that building it felt like I was using 2009 tech, not 2003 tech.
After spending a few years in .NET land I couldn't help but feel that Java UI tech has missed the boat. Maybe JavaFX will address this, but that represents yet another investment of time and effort, which still doesn't have the cross-platform payoff. I'm more likely to target Silverlight if I just want to run on Mac and Windows!
So, if someone needs to build a (true) cross platform app today, the only viable choice seems to be good old HTML + CSS + Javascript. When you really need a local/desktop app your choices are less clear. The closet idealist in me would like to have the 'one true way' to build rich cross-platform desktop apps, but at the moment I just don't see it. Sigh...



