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