Look-and-Feel Customization
In this section, we’ll look at 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.
Modification of Component Properties
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
component hierarchy, java.awt.Component
defines a number of
fundamental properties, including foreground
, background
, and 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.
Bear in mind that platform-specific L&F constraints on the rendering of certain components may prevent some property changes from being honored. For example, Mac buttons are always the same color.
Modification of the UI Defaults
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 UIResource
s come into play. There ...
Get Java Swing, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.