Java 1.7 – Swing

Since Java 1.7, in addition to the default Metal Look and Feel from Swing, Nimbus is shipped. You can activate the Nimbus Look and Feel simply by providing a parameter for the java command.

java -Dswing.defaultlaf=javax.swing.plaf.nimbus.NimbusLookAndFeel MyApp

See the documentation for more information about Nimbus.

Advertisements

How to create a java GUI quickly?

I had to create a simple Java GUI for my diploma thesis. So I asserted, how I can do this. After quite some research, I found a solution which reduces the amount of code needed using some of the best technologies in combination:

1. GUI Tool

In order to create the GUI, WindowBuilder Pro should be used. It was a commercial software from Instantiations. However, Instantiations was bought by Google and all their tools have been released under an OpenSource License and are now available for free.

2. Layout

Currently, the best layout manager for a Swing GUI is MigLayout. It is announced to be inside JDK7. This layout works seamlessly in the WindowBuilder Pro.

3. Controller and Models

For the implementation of the Controller and the models, I suggest Groovy. This reduces the amount of Code needed for this kind of work.

4. Binding

Then, the model elements have to be associated to GUI elements back and forth. For this purpose, WindowBuilder Pro uses the BeansBinding JSR. This is not worked on anymore, but does work alright. In combination with Groovy, it is really very very easy to do. Just use the editor for setting up the bindings and annotate the Groovy Class with @Bindable. For Lists use the ObservableList from the BeansBinding Jar.

Summary

Using Groovy (with @Bindable) and WindowBuilder Pro, I have built an amazing Swing GUI in no time. With really, really small amount of code. You should try it out, too!