// Changing the look and feel import java.awt.*; import java.awt.event.*; import javax.swing.*; public class PLAFApp extends JPanel { Container thisPanel = this; private JLabel lbl = new JLabel("Hi there"); private JButton btn = new JButton("Hide it"); private JButton nix = new JButton("Motif"); private JButton win = new JButton("Windows"); private JButton mtl = new JButton("Metal [Java]"); public PLAFApp() { btn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (lbl.isVisible()) { lbl.setVisible(false); btn.setLabel("Show it"); } else { lbl.setVisible(true); btn.setLabel("Hide it"); } } }); add(lbl); add(btn); add(nix); add(win); add(mtl); nix.addActionListener(new ChangeFeel()); win.addActionListener(new ChangeFeel()); mtl.addActionListener(new ChangeFeel()); } public class ChangeFeel implements ActionListener { public void actionPerformed(ActionEvent ae) { JButton clicked = (JButton) ae.getSource(); try { if (clicked == nix) UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); else if (clicked == win) UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); else if (clicked == mtl) UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); Container c = thisPanel; while (! (c instanceof JFrame)) c = c.getParent(); JFrame f = (JFrame) c; SwingUtilities.updateComponentTreeUI(f); } catch (Exception e) { e.printStackTrace(); } } } public static void main(String[] args) { PLAFApp pa = new PLAFApp(); GApp app = new GApp("The First App", pa); app.setSize(250, 100); app.show(); } }