Java Reference
In-Depth Information
Listing 20-9.
Custom Look and Feel
import javax.swing.UIDefaults;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
public class MyWindows extends WindowsLookAndFeel {
public String getID() {
return "MyWindows";
}
public String getName() {
return "MyWindows Look and Feel";
}
public String getDescription() {
return "The MyWindows Look and Feel";
}
public boolean isNativeLookAndFeel() {
return false;
}
public boolean isSupportedLookAndFeel() {
return true;
}
}
If you use this Swing class on a non-Windows machine, you can get the look and feel to be
the Windows look and feel. Just set your look and feel to be
MyWindows
and make the look and
feel class file available. The class file only needs to be available in your
CLASSPATH
and will be
started with the following command line:
java -Dswing.defaultlaf=MyWindows ClassFile
For the Windows look and feel change to work properly, you need to provide the image
files used for the icons of the look and feel from within the
icons
subdirectory of the
MyWindows
directory structure. Table 20-9 lists those icons appropriate to the predefined look and feel
types. The
MyWindows
look and feel needs all of the Windows image files.
■
Note
Although Ocean is a theme of Metal, it does provide its own set of images.
Table 20-9.
Look and Feel Image Files
File Name
Basic
Metal
Motif
Ocean
Windows
close-pressed.gif
X
close.gif
X
collapsed-rtl.gif
X
collapsed.gif
X
computer.gif
X