LAF系统是Swing的强大特性之一,它使得Java应用程序能够像原生程序一样被装饰起来。。通过改变程序的外观,你能够人们对你的程序的看法。
Java的Swing库缺省使用Metal LAF,但所有版本的Swing都带有包含了Motif LAF的ui.jar。另外,Windows版本的Swing包含Windows LAF,OS X版本的则包含Mac LAF。
try {
UIManager.setLookAndFeel("javax.swing.plaf.motif.MotifLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.windows.WindowsLookAndFeel");
//UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//UIManager.setLookAndFeel("com.apple.mrj.swing.MacLookAndFeel");
} catch(ClassNotFoundException cnfe) {
cnfe.printStackTrace( );
} catch(InstantiationException ie) {
ie.printStackTrace( );
} catch(IllegalAccessException iae) {
iae.printStackTrace( );
} catch(UnsupportedLookAndFeelException ulafe) {
ulafe.printStackTrace( );
}
// 'frame' 是最高层的组件
SwingUtilities.updateComponentTreeUI(frame);