Friday, February 13, 2009

How to change the System L&F in Java

Today, I have been requested to change the look and feel of a small Java application for which we don't have the source code. The reason for this was to workaround a bug in the Java 5 GTK look and feel implementation, which was preventing the application from starting up in some of our Linux boxes using GTK 2.3

My first proposal was to do as Sun says, and specify the “swing.defaultlaf” system property at the Java command-line, but it didn't work at all. So, the application is setting the Look and Feel programmatically. Too bad.

After executing the application in Windows and Linux, it was clear that the specified look and feel was the system one. So, how to change the class name returned by UIManager.getSystemLookAndFeelClassName()? Surprisingly, Google was not of much help here!

So, I went to the source; I mean, the JDK javadocs and source code. And there, I found the answer. Instead of setting the “swing.defaultlaf” system property, you have to set the “swing.systemlaf” one. And that's all. Simple, isn't it?

No comments:

Post a Comment