1. 利用UIManager.setLookAndFeel()方法(这个方法需要传入正确的Look and Feel名称,如下)设置新的Look and Feel外观。
Metal风格——"javax.swing.plaf.metal.MetalLookAndFeel"
Motif风格——"com.sun.java.swing.plaf.motif.MotifLookAndFeel"
Windows风格——"com.sun.java.swing.plaf.windows.WindowsLookAndFeel"
2. 用SwingUtilities.updateComponentTreeUI()方法改变外观。
示例代码:
try {
UIManager.setLookAndFeel(lnfName);
SwingUtilities.updateComponentTreeUI(frame);
}
catch (UnsupportedLookAndFeelException ex1) {
System.err.println("Unsupported LookAndFeel: " + lnfName);
}
catch (ClassNotFoundException ex2) {
System.err.println("LookAndFeel class not found: " + lnfName);
}
catch (InstantiationException ex3) {
System.err.println("Could not load LookAndFeel: " + lnfName);
}
catch (IllegalAccessException ex4) {
System.err.println("Cannot use LookAndFeel: " + lnfName);
}