O'Reilly logo

Java Examples in a Nutshell, 3rd Edition by David Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Look-and-Feel Preferences

A number of the examples in this chapter have used the utility class LookAndFeelPrefs to install the user's preferred look-and-feel and create a JMenu listing available look-and-feel choices. LookAndFeelPrefs is shown in Example 11-29. It demonstrates the use of the javax.swing.UIManager class for querying and setting look-and-feels, and also demonstrates the use of the java.util.prefs package (new in Java 1.4) for retrieving and storing persistent user preferences.

LookAndFeelPrefs relies on the list of installed look-and-feel implementations returned by UIManager.getInstalledLookAndFeels( ). By default (in Java 1.4.2, at least) this method returns three look-and-feels: the Java "Metal" look-and-feel, the Motif (CDE) look-and-feel, and the Windows look-and-feel. This is true even on non-Windows platforms for which the Windows look-and-feel is unsupported. Java 1.4.2 also ships with a GTK look-and-feel, which mimics the Linux GTK look-and-feel, but getInstalledLookAndFeels( ) does not know about it. To make this new look-and-feel available to the LookAndFeelPrefs example, you'll need to create a swing.properties file and place it in the jre/lib/ directory of your Java SDK. The contents of the file should look like this:

# Add the Mac look-and-feel if your SDK comes with it. # Delete the Windows look-and-feel if it is not supported on your platform. swing.installedlafs = gtk,metal,motif,win swing.installedlaf.gtk.name = GTK Look and Feel, swing.installedlaf.gtk.class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required