
434
|
Chapter 11, Native Integration and Packaging
#86 Make Quick Look and Feel Changes
HACK
H A C K
#86
Make Quick Look and Feel Changes
Hack #86
Customize Metal with custom fonts, colors, and even system-bound
properties using just a few API calls.
Swing is a very customizable UI toolkit. The most advanced way of chang-
ing the look of your application is with a custom Look and Feel (L&F), but
they can be tricky to build. Swing’s L&F API is very complicated, often
requiring thousands of lines of code for a complete custom theme. Fortu-
nately, if you want to change just a few colors or fonts, the L&F API pro-
vides a much easier way. This hack shows how to create simple visual
changes using UI properties.
Look and Feel Properties
Every Look and Feel that extends the javax.swing.plaf.basic.* classes can
accept special properties that define the behavior of each Swing component.
For example, there is property to control the background color of every
JButton. If you change this property at the start of your program, then every
JButton you create will have that background color.
The UI properties are stored in a static class called the
UIManager. To set a
property, just put in the name of the property and a value object like a
Color. To set the background color of a button to green, you would do
something like this:
UIManager.put("Button.background", Color.green);
It is important to set these properties before ...