import javax.swing.*; import java.awt.event.*; import java.awt.*; public class LAFTest3 extends JFrame { JComboBox c = new JComboBox(); JTextField t = new JTextField(30); LAFTest3 outermostWindow = this; public static void main(String[] args) { LAFTest3 frame1 = new LAFTest3(); frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame1.setSize(500, 80); frame1.setVisible(true); LAFTest3 frame2 = new LAFTest3(); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setSize(500, 80); frame2.setVisible(true); LAFTest3 frame3 = new LAFTest3(); frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame3.setSize(500, 80); frame3.setVisible(true); } private class LAFChoice { UIManager.LookAndFeelInfo lafi; public LAFChoice (UIManager.LookAndFeelInfo lafi) { this.lafi = lafi; } public String toString() { return lafi.getName(); } public String getClassName() { return lafi.getClassName(); } } // class LAFChoice public LAFTest3() { UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels(); for (int i = 0; i < lafs.length; ++i) { c.addItem(new LAFChoice(lafs[i])); } t.setEditable(false); c.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ JComboBox box = (JComboBox)e.getSource(); LAFChoice choice = (LAFChoice)box.getSelectedItem(); try { UIManager.setLookAndFeel(choice.getClassName()); t.setText(choice.getClassName()); } catch (Exception exc) { System.err.println("Error loading " + choice.getClassName() + ": " + exc); } SwingUtilities.updateComponentTreeUI(outermostWindow); } }); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(t); cp.add(c); } } // class LAFTest3