CHANGE THE LOOK AND FEEL OF YOUR JAVA APPLICATIONS Java applications often seem very plain next to their native counterparts. However, it's easy to jazz them up by changing the Swing Look and Feel (LAF). The LAF system is one of Swing's most powerful features, allowing Java applications to masquerade as native programs. By changing the look, you can change how people view the application. Java's Swing library runs by default in the Metal LAF, but all versions of Swing ship with a ui.jar that contains a Motif LAF. In addition, the Windows version has a Windows LAF, and the OS X version has a Mac LAF. Follow this example to change the LAF in Java: try { UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel"); // UIManager.setLookAndFeel("javax.swing.plaf.windows.WindowsLookAndFeel"); // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); // UIManager.setLookAndFeel("com.apple.mrj.swing.MacLookAndFeel"); } catch(ClassNotFoundException cnfe) { cnfe.printStackTrace( ); } catch(InstantiationException ie) { ie.printStackTrace( ); } catch(IllegalAccessException iae) { iae.printStackTrace( ); } catch(UnsupportedLookAndFeelException ulafe) { ulafe.printStackTrace( ); } // 'frame' is an example top level component SwingUtilities.updateComponentTreeUI(frame); While the UIManager gets updated inside the try/catch block, the existing components are not updated. This is handled by the call to the SwingUtilities method, updateComponentTreeUI(java.awt.Component). By passing the top-level component of the graphical user interface (GUI) to this method, all of the styles will be updated. The Metal LAF is slightly more powerful than the others because it's themeable. Changing the background color is only one of the wide ranges of themeable properties in the Metal LAF that can be set with the UIManager for a particular component or for the whole platform with a customized Theme. For example, you can set the background of a component in any LAF to be a certain color with: UIManager.put("Tree.background", Color.yellow); However, the Metal LAF allows you to modify all backgrounds across the whole look and feel with the BackgroundTheme class: package com.generationjava.swing; import java.awt.Color; import javax.swing.plaf.ColorUIResource; import javax.swing.plaf.metal.DefaultMetalTheme; public class BackgroundTheme extends DefaultMetalTheme { private final ColorUIResource resource; public BackgroundTheme(Color color) { this.resource = new ColorUIResource(color); } public ColorUIResource getSecondary3( ) { return this.resource; } } The BackgroundTheme class can be used in the following way: import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UIManager; import javax.swing.plaf.metal.MetalLookAndFeel; .... MetalLookAndFeel.setCurrentTheme(new BackgroundTheme( Color.yellow ) ); try { UIManager.setLookAndFeel( new MetalLookAndFeel( ) ); } catch(ClassNotFoundException cnfe) { cnfe.printStackTrace( ); } catch(InstantiationException ie) { ie.printStackTrace( ); } catch(IllegalAccessException iae) { iae.printStackTrace( ); } catch(UnsupportedLookAndFeelException ulafe) { ulafe.printStackTrace( ); } NOTE: Once the MetalLookAndFeel is modified, it needs to be reloaded with the setLookAndFeel method. ----------------------------------------