如何更改Netbeans Java(项目GUI)的外观和感觉?

时间:2018-05-19 21:12:02

标签: java swing look-and-feel

每次运行我的Java SE(swing)程序时,它都以 Nimbus 外观和感觉运行,但我的设计基于 Windows 外观,我该怎么办?使它运行我的默认程序具有Windows外观而不是Nimbus?

我在几个地方搜索过,他们说要改变" Nimbus"到" Windows"这对我不起作用。

try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            javax.swing.UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

1 个答案:

答案 0 :(得分:0)

替换...

try {
    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            javax.swing.UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

更像是......

try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(ValidFileGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); 
}

您可以阅读How to Set the Look and Feel更多详情