在程序中设置LookAndFeel,使用如下代码的红色部分(注:这种方法是在程序开始时进行的设置):
public
static
void
main(String[] args)
...
{ try ...{ UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception e) ...{ } new SwingApplication(); //Create and show the GUI.}
可设置以下几种不同的LookAndFeel:
UIManager.getCrossPlatformLookAndFeelClassName()
UIManager.getSystemLookAndFeelClassName()"com.sun.java.swing.plaf.gtk.GTKLookAndFeel""javax.swing.plaf.metal.MetalLookAndFeel""com.sun.java.swing.plaf.windows.WindowsLookAndFeel""com.sun.java.swing.plaf.motif.MotifLookAndFeel"
要想在程序运行期间来改变LookAndFeel,使用以下的代码:
UIManager.setLookAndFeel(lnfName);SwingUtilities.updateComponentTreeUI(frame);frame.pack();