Swing中的几种默认样式

更新时间 🔔🕙 2021年5月4日

在jdk1.8中,已经内置了几种swing样式,为
Metal
Nimbus
CDE/Motif
Windows
Windows Classic

java中设置swing外观的示例代码(在main函数的刚开始就执行):

try {
javax.swing.UIManager.LookAndFeelInfo[] installedLookAndFeels=javax.swing.UIManager.getInstalledLookAndFeels();
for (int idx=0; idx<installedLookAndFeels.length; idx++)
if ("Nimbus".equals(installedLookAndFeels[idx].getName())) {
javax.swing.UIManager.setLookAndFeel(installedLookAndFeels[idx].getClassName());
break;
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Antenna.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
转载请备注引用地址:编程记忆 » Swing中的几种默认样式