The MultiLookAndFeel

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

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

The idea behind the 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.9 gives a high-level view of how this might work.

The multiplexing look-and-feel

Figure 26-9. The multiplexing look-and-feel

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

Get Java Swing 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.