import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class ChangeLookAndFeel extends JFrame implements ActionListener { // button panel private JPanel buttonPanel = new JPanel(); public ChangeLookAndFeel() { buttonPanel.setLayout(new GridLayout(1, 3, 4, 4)); // Create the buttons. JButton b = new JButton("Metal"); b.addActionListener( this ); buttonPanel.add( b ); b = new JButton("Windows"); b.addActionListener( this ); buttonPanel.add( b ); b = new JButton("Motif"); b.addActionListener( this ); buttonPanel.add( b ); // Layout. Container c = getContentPane(); c.setLayout(new BorderLayout()); c.add(new JLabel("Select a look and feel"), BorderLayout.NORTH); c.add(buttonPanel, BorderLayout.CENTER); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); pack(); setVisible(true); } public void actionPerformed( ActionEvent e ) { try { //One call to UIManager.setLookAndFeel is all it takes to //change the apperance of the entire application. if ( e.getActionCommand().equals( "Metal" ) ) UIManager.setLookAndFeel( new javax.swing.plaf.metal.MetalLookAndFeel() ); else if ( e.getActionCommand().equals( "Windows" ) ) UIManager.setLookAndFeel( new com.sun.java.swing.plaf.windows.WindowsLookAndFeel() ); else if ( e.getActionCommand().equals( "Motif" ) ) UIManager.setLookAndFeel( new com.sun.java.swing.plaf.motif.MotifLookAndFeel() ); } catch ( UnsupportedLookAndFeelException ex ) { System.out.println( ex.getMessage() ); } //Make the components redraw themselfs using the new look and feel. SwingUtilities.updateComponentTreeUI( this ); } public static void main(String[] args) { new ChangeLookAndFeel(); } }