While trying to figure out how to best add theme capabilities to my pet project (J.I.M. – a jxta based instant messenger) I revisited the LookAndFeel feature for java and found that the new SynthLookAndFeel feature shipping officially in java 5 might be a quite time-saving way to accomplish great pluggable theming for java UI applications.
What I found was somehow a lack of documentation and tutorials for the SynthLookAndFeel framework. There are specifications available, but no good documentation or best practices.
Further, there is one other major pitfall you run into quite fast:
This is quite cumbersome, because some (including me) would expect that there is some default theme available that you can easily supplement with your own specific widget looks. Actually, there is no such thing like a default theme. Nevertheless, the SynthLAF feature of java 5 looks worth going the hard way: Design a full theme on your own. So here we go. To use SynthLookAndFeel I did:
CODE:
SynthLookAndFeel laf = new SynthLookAndFeel();
UIManager.setLookAndFeel(laf);

The screenshot on the right has the plain Action menu open; I pressed the ‘Find Buddies’ entry and revealed a flaw in the current SynthLookAndFeel implementation. Without an explicit binding, some JTables are not operable. I guess it’s a bugs, but nevertheless, it makes a synth theming task harder than needed.
JTables need a minimal explizit SynthLookAndFeel color binding for the TEXT_BACKGROUND and TEXT_FOREGROUND colors in the “SELECTED” synth state. If you fail to bind those colors, you will either get a NullPointerException in javax.swing.JTable.setSelectionForeground or javax.swing.JTable.setSelectionBackground. This is rather buggy, because no other widget appears to need any synth binding for any state and in consequence I wasted time without realizing that this must be a bug in java 5.
Anyway, after loading the following synth style file, I finally came to the search gui I wanted to themify.
CODE:
<synth>
<style id=”juxim-table”>
<state value=”SELECTED”>
<color value=”#FFFFFF” type=”TEXT_BACKGROUND”/>
<color value=”#0000FF” type=”TEXT_FOREGROUND”/>
</state>
</style>
<bind style=”juxim-table” type=”region” key=”Table”/>
</synth>
As expected “no theme at all” is quite unusable. It rather looks unfunctional and indistinct. In fact, there are no widgets visible to the user; all looks plain. Below you can see the jxtaim search dialog I saw with “no theme” applied.
I started looking for a full synth theme, but found only commercial ones. So I decided to setup my own theme. I took screenshot from my individual gnome desktop – and extracted those beautiful widgets to develop a shiny initial theme.
You can see the result below. The theme is still intermediate (aka incomplete), but I expect to finish the job in a week or two …