java swing中改变改变Look and Feel外观的方法和步骤_

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);
}

 

 

你可能感兴趣的:(java,windows,swing,sun)