import javax.swing.*; import java.awt.event.*; import java.awt.*; public class LAFTest2 extends JFrame { JComboBox c = new JComboBox(); JTextField t = new JTextField(30); LAFTest2 outermostWindow = this; public static void main(String[] args) { LAFTest2 frame = new LAFTest2(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(500, 80); frame.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 LAFTest2() { 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 LAFTest2