Java Reference
In-Depth Information
Figure 14-15. Look and feel switcher under Mac OS X
Example 14-10
shows the code that implements the look and feel switcher. It's pretty
straightforward based on what we've seen already. The only neat trick is that I've set the se-
lected button back to what it was if the look and feel that the user selects is not available.
Example 14-10. LNFSwitcher.java
public
public class
LNFSwitcher
{
/** The frame. */
protected
class
LNFSwitcher
protected
JFrame theFrame
;
/** Its content pane */
protected
protected
Container cp
;
/** Start with the Java look-and-feel, if possible */
final
final static
static
String PREFERREDLOOKANDFEELNAME
=
"javax.swing.plaf.metal.MetalLookAndFeel"
;
protected
protected
String curLF
=
PREFERREDLOOKANDFEELNAME
;
protected
protected
JRadioButton previousButton
;
/** Construct a program... */
public
public
LNFSwitcher
() {
super
super
();
theFrame
=
new
new
JFrame
(
"LNF Switcher"
);
theFrame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
cp
=
theFrame
.
getContentPane
();
cp
.
setLayout
(
new
new
FlowLayout
());
ButtonGroup bg
=
new
new
ButtonGroup
();