O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 UIResources come into play. There ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required