Pluggable Look-and-Feel
We mentioned before that Swing components can easily change their appearance, like master spies or thespians. Generally, different kinds of components within an application have coordinated appearances that are similar in some way. For example, they probably use the same font and the same basic color scheme. The collection of appearances and common behavior of GUI components is called a look-and-feel (L&F).
Part of the job of designing a GUI for an operating system is designing the L&F. Mac OS, therefore, has its own distinctive L&F, as does Windows. Java offers several different L&F schemes for Swing components. If you’re adept at graphic design, you can write your own L&F schemes and easily convince Swing to use them. This chameleon-like ability to change appearance is called pluggable look-and-feel, sometimes abbreviated PLAF (don’t pronounce that out loud if others are eating).
Seeing is believing. Here’s an example that creates a handful of Swing components. Menu items allow you to change the L&F dynamically while the application is running:
//file: QuickChange.javaimportjava.awt.*;importjava.awt.event.*;importjavax.swing.*;publicclassQuickChangeextendsJFrame{publicQuickChange(){super("QuickChange v1.0");createGUI();}protectedvoidcreateGUI(){setSize(300,200);// create a simple File menuJMenufile=newJMenu("File",true);JMenuItemquit=newJMenuItem("Quit");file.add(quit);quit.addActionListener(newActionListener(){public ...