In this section, we’ll look at a variety of different ways that you can change the way components in your application appear. We’ll start with the simplest approach—making property changes on a per-component basis—and work our way through several increasingly powerful (and complicated) strategies. In the last section, we’ll show you how to build your own L&F from the ground up.
This is the most obvious way to change the look of a component, and
it’s certainly not new to Swing. At the very top of the Java
java.awt.Component defines a
number of fundamental properties, including
font. If you want to change the way a specific
component looks, you can always just change the value of these
properties, or any of the others defined by the specific components
you are using. As we said, this is nothing new to the Swing
PLAF architecture, but we don’t want to lose
sight of the fact that you can still make many changes in this way.
Modifying component properties lets you customize individual components. But what if you want to make more global changes? What if you want to change things that aren’t exposed as component properties?
This is where
UIResources come into play. There are more than 300 different resources defined by the Swing L&Fs that you can tweak to change the way the components are displayed. These resources include icons, borders, colors, ...