Java Reference
In-Depth Information
frame.add(comboBox, BorderLayout.NORTH);
frame.add(panel, BorderLayout.SOUTH);
frame.setSize(350, 150);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
Note Notice that the actual look and feel change is made in a call to EventQueue.invokeLater() .
This is necessary because the handling of the current event must finish before you can change the look and
feel, and the change must happen on the event queue.
Besides programmatically changing the current look and feel, you can start up a program
from the command line with a new look and feel. Just set the swing.defaultlaf system property
to the look and feel class name. For instance, the following startup line would start the ChangeLook
program, making the Motif look and feel the initial look and feel.
java -Dswing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel ChangeLook
If you want a different default look and feel every time a program starts up, you can create
a file, swing.properties , under the Java runtime directory ( jre by default) with the appropriate
setting. The swing.properties file needs to be in the lib directory of the Java runtime directory
( jre/lib ). For instance, the following line would cause the initial look and feel to be Motif all
the time, unless changed programmatically or from the command line.
swing.defaultlaf=com.sun.java.swing.plaf.motif.MotifLookAndFeel
In addition to the swing.defaultlaf setting, the swing.properties file supports several
other entries, as listed in Table 20-2. Each property allows you to override the default settings
for the predefined look and feel setup. The auxiliary and multiplexing look and feel classes
support accessibility, among other things. They will be discussed later in this chapter, in the
“Using an Auxiliary Look and Feel” section.
Table 20-2. Swing Properties File Entries
Property Name
Default Value When Unset
swing.defaultlaf
javax.swing.plaf.metal.MetalLookAndFeel
swing.auxiliarylaf
None
swing.plaf.multiplexinglaf
javax.swing.plaf.multi.MultiLookAndFeel
swing.installedlafs
Metal, Motif, Windows
swing.installedlaf.*.name
N/A
swing.installedlaf.*.class
N/A
 
Search WWH ::




Custom Search