O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

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 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.

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.

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 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, ...

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