import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
public class LNFExample extends JFrame {
private String[] lnfs = { "javax.swing.plaf.metal.MetalLookAndFeel",
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
"com.sun.java.swing.plaf.motif.MotifLookAndFeel" };
private String[] lnfs2 = { "MetalLookAndFeel", "WindowsLookAndFeel",
"MotifLookAndFeel" };
private JComboBox combo = new JComboBox(lnfs2);
public LNFExample() {
super("Example");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setAlwaysOnTop(true);
this.setLocationByPlatform(true);
this.setSize(320, 480);
combo.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
changeLF(lnfs[combo.getSelectedIndex()]);
}
public void popupMenuCanceled(PopupMenuEvent e) {
}
});
this.add(combo, BorderLayout.NORTH);
this.add(new JScrollPane(new JTextArea(
"Try the various look and feels for Swing!")),
BorderLayout.CENTER);
this.add(new JButton("JButton"), BorderLayout.SOUTH);
this.add(new JLabel("JLabel"), BorderLayout.WEST);
this.add(new JSlider(JSlider.VERTICAL), BorderLayout.EAST);
this.setVisible(true);
}
public void changeLF(String lnfName) {
try {
UIManager.setLookAndFeel(lnfName);
} catch (Exception e) {
}
SwingUtilities.updateComponentTreeUI(this);
}
public static void main(String[] args) {
new LNFExample();
}
}