Java Swing 2.0

I believe that there is a need for a proper Swing 2.0 which is not JavaFX-based, but a true, desktop focused, Java (the language)-based framework. My vision is one shared by numerous others, and in a brief discussion (via twitter no-less), a number of us enumerated what we believe a Swing 2.0 needs. The following list is a brief overview of what Swing 2.0 should be:

  • Generics-based. No more should we put our objects into various Swing data models and components only to receive Object back. It should be possible to create swing data models and components with the data type specified. There is work in this direction already with the Swing-generics project, although progress is slow. Swing 2.0 should include this project instead of duplicating work.
  • Support for enumerations where obvious. There are numerous places where public static final ints could be replaced by enumerations. This leads to a cleaner API.
  • Support for varargs. Once again, there are places where varargs could be used to clean the API.
  • Improved support for collection frameworks. That is, we should not still be requiring Vector lists, unless syncrhronization is absolutely necessary.
  • Stricter enforcement of event dispatch thread (EDT) rules. Swing is slow (or so the saying goes). This is untrue, but is unfortunately the perception. This perception exists because developers don’t understand how to deal with the EDT. There exists code out there now that can enforce the rules surrounding the EDT by essentially throwing exceptions when components are handled off of the EDT, and when tasks take too long that should not be run on the EDT. By default, Swing 2.0 would enforce EDT checking, throwing all exceptions discovered. This may make developers unhappy, but the end result is better programs and happier users. It is worth it.
  • Improved support for bean binding and validation. I won’t go so far as to say we need properties, largely because I don’t know enough to have an informed opinion, and I know that by saying we need properties Swing 2.0 instantly becomes far less possible without major Java language updates. But, I know that projects such as the JGoodies beans binding and validation tools are very useful, and make creating data-driven user interfaces far easier and rapid. It may make sense to incorporate these kinds of frameworks into Swing 2.0 to enable users to focus on the business logic, and not getting data to and from the user.

What you may note is missing is any mention of new components, new Look and Feels, etc. That is not my interest – in my opinion Swing 2.0 is a cleanup of the code beneath the existing Swing components. It would be ideal if Swing 2.0 could be API compatible with Swing 1.0, but I would not be adverse to Swing 2.0 becoming a separate Swing library in its own package (i.e. javax.swing2). This would allow for API cleanups, and repurposing of existing API method names.

What  do you think? Do we need a Swing 2.0 that has the roughly the above features (make any suggestions you have). Is it too little too late for desktop Java (personally I think not, obviously)? Please, leave any comments or thoughts that you may have – let’s get the discussion started.

Swing links of the week, January 26th

Another week, another Swing links. Thanks to everyone sending me links – please keep it up! Also, at the end of this post I have a request for everyone to help me out, so please be sure to read it!

Here are some links regarding Swing and Java GUI’s you may have missed in the last week:



  • Charles Humble wrote in to let me know that he has an interview with Stephen Chin regarding WidgetFX. I mentioned WidgetFX in last weeks post, but this is another interview, and is a little more in-depth.
  • Announced this week is that jSilhouette has joined the JFXtras project. The JFXtras project is an open effort to fill in the gaps in the current JavaFX library, whereas jSilhouette provides a collection of Java2D shapes that can be used in several modes, and now that it is part of JFXtras, these shapes can also be used in JavaFX. To allow for this immediately, both projects announced new releases.
  • Swing links regular Alex Ruiz made a number of announcements regarding his FEST Java library that provides a fluent interface for functional Swing GUI testing. These include a post on how to test drag and drop in JavaFX using FEST, as well as announcements that the FEST developer team is growing.
  • Jasper Potts has posted a blog discussing how he made the video for Devoxx/ using JavaFX.  This post is a good tutorial to anyone wanting to get an understanding of animation in JavaFX, with a lot of code, diagrams, and a Java Web Start link.
  • Osvaldo Pinali Doederlein has posted his first impressions of working with JavaFX, in terms of the language, and the performance of programs written in JavaFX. He writes JavaFX Balls: the JavaFX version of the Bubblemark RIA benchmark, and makes available all related source code.
  • Coming in just before I posted this weeks Swing links, Jim WeaverDean Iverson posted about how to do spotlight effects in JavaFX. As usual, he has included a lot of code samples.

That’s it for another week. Three weeks down, who knows how many more to go! Now that you have an idea of how Swing links is working under my direction, I’d love to hear your thoughts. Am I being too thorough, or not thorough enough? Do I include all the posts you’ve come across, or do I post too many links? Is my analysis too long or too short? I’d love your thoughts, as it’ll let me refine things.

Thanks, and have a great week!

Swing links of the week, January 18th

Here are some Java GUI-related news items you may have missed in the last week…I hope you enjoy them. If you think I missed anything, let me know in the comments. Have a great week!

  • Firstly a post I missed last week: Jacek Furmankiewicz has announced the availability of the Swing JavaBuilder PDF book that aims to provide a more thorough documentation of the project’s goals and features.
  • Kirill Grouchnikov continues improving his flamingo JRibbon and substance projects, bringing the flamingo look and feel much closer to that of Office 2007. Behind the scenes on the mailing lists he and Andrey Eremchenko have been working very hard to bring the experience of JRibbon much more closer to Office 2007’s ribbon.
  • Alex Ruiz continues his series on testing JavaFX UIs. This is part four, with the previous three available here (parts 1, 2, 3). This post focuses on automating the build process of a combined Java and JavaFX project using Maven.
  • Speaking of Alex Ruiz, he has just announced the avilability of the FEST-Swing 1.0 release. FEST-Swing is a Java library that provides a fluent interface for functional Swing GUI testing. This library provides an easy-to-use API that makes creation and maintenance of GUI tests easy.
  • James Sugrue interviews Stephen Chin about his WidgetFX project. WidgetFX is a desktop widget platform written in the JavaFX Script language. It can run widgets written in either JavaFX Script or Java.
  • Ken Orr at Exploding Pixels writes about how he managed to write an image to disk, accessing it through the Mac OS NSImage:// protocol.
  • Jim Crossley looks at the improvements made to Java Applets in Java 6 Update 10. Yes, I know this is old news, but I thought that this summary was pretty good, and provides a good amount of justification for anyone lingering on older releases to upgrade.
  • Jasper Potts has posted a link to his JavaOne 2008 talk about the Nimbus look and feel. I have yet to use Nimbus in any of my Java projects, instead preferring to maintain the look and feel of the current users operating system. This has always been something that has confused me a little – how popular are the custom Sun developed look and feels such as Metal and Nimbus? Is it the best use of engineering resources?
  • Are you interested in learning more about JavaFX? If so, Jim Weaver and Sang Shin are running a free ‘15-Week JavaFX Programming (with Passion!)’ online course.
  • Jean-Francois Poilpret posts about best practices when doing layouts in Swing. This blog post does tend to focus on his DesignGridLayout layout manager, but even if you aren’t using it there are a number of good tips in this post that I recommend all UI designers/developers to follow in their own projects.
  • With the availability of LGPL licensing being announced this week for QT, there is some discussion that Java may have just got a brand new components framework, accessible through QT-Jambi. Joe Walnes blog post was the first I saw discussing this. I definitely recommend giving the webstart link a try – it is actually quite impressive, although I’m not 100% certain of QT-Jambi’s licensing plans.
  • Finally, all developers: heed this advice.

That’s it for Swing links this week, I hope you enjoyed it. If you have any links I missed or feedback (both positive and negative), please leave a comment or send me an email. Cheers!

Swing links of the week, January 13th

Given that I am heavily engaged in the development of Java Swing-based applications, and the recent ‘freezing’ of Kirill’s blog posts regarding popular Swing news, I thought I would try my best to pick up the slack.

I think it is probably worthwhile that I quickly state that my interests are primarily in Swing, so I am not overly up with the play in other areas that Kirill frequently blogged about, such as JavaFX and Groovy. Regardless, I will try my best, and if you have any news, please post it to me at [email protected]. Without any further ado, here are some Swing links you might have missed in the past week:

  • A few years ago the Swing team made Aerith, which demoed various cool things that could be done with Swing. This week the Aerith Netbeans project was announced by Julian Gamble. This project strips out the major components of Aerith, and makes them available to all Swing developers. There is also a number of videos which introduce you to this project.
  • Jean-Francois Poilpret has announced the RC1 release of DesignGridLayout. Any new layout to the Swing world is generally much appreciated, given the lack of development of new layouts since Swing was first developed. I should also link to JGoodies Forms layout (which I use heavily), and MiG Layout (which I have yet to use).
  • Speaking of layouts, Amy Fowler has posted a blog post about layouts for JavaFX.
  • Alex Ruiz continues his blog series on testing JavaFX user interfaces with part 3 (part 1 and part 2 are also available). The testing is accomplished using his FEST Swing DSL-oriented Swing testing library.
  • Osvaldo Pinali Doederlein has posted a blog post attempting to clarify JavaFX FUD that exists. I think he clarifies that Swing and JavaFX, whilst competing in some senses, have different focuses also – JavaFX can be far more lightweight, allowing for it to be used in mobile devices far more readily than Swing will ever be.
  • And finally, everyones favourite blogger Joel Spolsky posted a blog about the wordy Java installation process. I agree that there is a job for someone within Sun to run through all these dialogs and try to simplify and clarify the message that Sun portrays to the outside world.

Basic XML Unmarshalling in Java

I frequently find myself groaning in agony over having to deal with more XML coming in to my various Java applications. I thought I would finally do something about it, so I wrote the code below. It is very simple, but performs the way I need it to. Basically, you give it a class that specifies the properties from the XML. Each field is annotated with the name that it correlates to in the XML string. Below is the code, and below that is an example.

The other class is a class that a user must provide. My test class is the following:

A sample execution would then be:

The output of this then becomes:

name: name 1, low: 76, high: 77
name: name 2, low: 1, high: 2
name: name 3, low: 3, high: 42

The reason why the output is above is because I have overridden the toString() method, but of course all of the fields are accessible just like any other publically accessible field.

Basic I know, but it is reusable, and I plan to make use of this code in the future to stop me having to groan in agony over dealing with XML text.