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

The MultiLookAndFeel

Before we get into creating our own L&F, we’ll take a quick detour to explore MultiLookAndFeel. This is the L&F that allows accessible interfaces to be incorporated into Swing applications. It can also be used to add sound effects, support for automated testing, and more.

By this point, you’re probably at least aware of the concept of accessibility as it applies to JFC and Swing. If you read Chapter 25, you’re aware of more than just the concept. The last piece of the accessibility puzzle is Swing’s multiple L&F support.

The idea behind MultiLookAndFeel is to allow multiple L&Fs to be associated with each component in a program’s GUI without the components having to do anything special to support them. By allowing multiple L&Fs, Swing makes it easy to augment a traditional L&F with auxiliary L&Fs, such as speech synthesizers or braille generators. Figure 26-10 gives a high-level view of how this might work.

MultiLookAndFeel and Auxiliary L&F

Figure 26-10. MultiLookAndFeel and Auxiliary L&F

In this diagram, we show a JButton in a multiplexing UI environment. The button’s UI delegate is actually a MultiButtonUI, which is contained in the javax.swing.plaf.multi package. This is a special delegate that can support any number of additional ButtonUI objects. Here, we show the default UI delegate (MetalButtonUI) and two (hypothetical) auxiliary delegates, AudioButtonUI and BrailleButtonUI.

The MultiButtonUI ...

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