Chapter 11, Native Integration and Packaging
#86 Make Quick Look and Feel Changes
SystemColor is a special subclass of Color that provides access to most of the
standard color settings of any operating system. It also has the special abil-
ity to update itself whenever the underlying system color changes. This
means if the user switches her native colors from a control panel, your appli-
cation will automatically update itself to reflect the new settings.
Instead of methods,
has a bunch of constants that define each
type of color from
activeCaptionText to windowBorder. The documentation is
minor, so you will need to play around with different settings to get the
effect you are looking for:
Color sysbg = SystemColor.control;
Color sysfg = SystemColor.controlText;
This code sets the background and foreground of every button to use the
control and controlText fields of SystemColor. With my computer set to use
the Desert theme, it looks like Figure 11-15.
If I change my window theme to high-contrast black, it looks like
UIManager properties give developers a simple way to customize the colors,
fonts, and borders of almost any Swing component. As an enhancement,
you could allow users to customize the colors themselves and store the val-
ues in a properties file.
Figure 11-15. Window with the Desert theme