2

在 Java 的 Mac 上使用 Netbeans GUI 构建器构建。

这是 Netbeans 中 GUI 的样子:

Netbeans 图形用户界面

当我点击预览时,它看起来并没有太糟糕,但有一些小的变化:

图形用户界面预览

最后,当我运行它时,它看起来像这样: - 可怕

外观和感觉

我认为这与 Java 的“外观和感觉”有关。我试过删除它,GUI 变得一团糟。那么我的选择是什么?正如您在 Netbeans 中看到的那样,当我运行它时,一切都是一团糟。

有任何想法吗?花了一天时间搞砸这个,至少可以说我受够了

4

3 回答 3

5

从外观上看,Netbeans 中的预览版使用的外观与Java 在运行应用程序时使用的外观不同。
但是,您可以尝试手动设置所需的外观。Oracle 提供了一个关于如何获取和设置外观的教程

于 2013-02-19T22:38:03.927 回答
5

在您的代码中的某些地方,Netbeans 会创建一个main方法(这将在 Netbeans 执行的类中,并且可能是您的主框架 - 我认为那将是SPPMainGUI

它看起来像这样(注意它可能是“折叠的”,所以你只会看到第一条评论和decs第二条评论(Look and feel setting code (optional)))

/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
 */
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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

通过单击边距中的小 + 展开代码块并将其替换for-loopUIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());如下

/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
 * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
 */
try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
    java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

当 afsantos 发现问题时,如果你能接受他的回答是正确的,我会很高兴的(并且改为对我投赞成票;),轻推,轻推,眨眼,眨眼,不要再说了)

于 2013-02-19T23:15:06.820 回答
1

正如您所提到的,它与外观和感觉有关,所以真的,如果找到 L&F Netbeans 默认使用的唯一问题。谷歌调出了这个页面。我引用,

在 NetBeans 7 中,默认外观自动设置为 Nimbus 外观。

来自甲骨文:

Nimbus 是在 Java SE 6 Update 10 (6u10) 版本中引入的一种经过优化的跨平台外观。

要启用 Nimbus 外观和感觉,只需在某处添加这些不言自明的行:

try {
    for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            break;
        }
    }
} catch (Exception e) {
    // If Nimbus is not available, you can set the GUI to another look and feel.
}
于 2013-02-19T23:14:56.247 回答