【问题标题】:Java swing application look and feel appears different in netbeans and eclipseJava swing 应用程序的外观在 netbeans 和 eclipse 中出现不同
【发布时间】:2014-06-04 05:45:07
【问题描述】:

我正在使用 Netbeans IDE 7.4 开发 java swing 应用程序,其中我试图将外观设置为原生。当我运行该应用程序时,其外观与 Windows 不同(我的操作系统是 Windows 8)。

我尝试将 eclipse 用于与我在代码中提供的外观和感觉相同的地方,例如:Nimbus、Window 等。

我想继续在 Netbeans 中开发这个应用程序,因为它的拖放功能可以节省大量编写 GUI 特定代码的时间。

以下是代码 sn-p,它在从 Eclipse 构建和运行时为我提供 Windows 外观,但在从 Netbeans 构建和运行时不提供 Windows 外观:

for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Windows".equals(info.getName())) {
            try {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (UnsupportedLookAndFeelException e) {
                e.printStackTrace();
            }
            break;
        }
    }

【问题讨论】:

    标签: java eclipse swing netbeans


    【解决方案1】:

    NetBeans IDE 生成代码,并在页边空白处用“[+]”折叠 - 乍一看并不明显。我相信 main 方法的开始,安装 Nimbus 外观。不太清楚,但看代码。

    在每种情况下,您似乎都在较早地执行 NetBeans 生成的代码,因为它们之间存在差异。只需在打开的项目中查找setLookAndFeel

    【讨论】:

    • 感谢您的建议,我知道在main 方法中我们需要做的第一件事就是设置UIManager。现在它对我来说很好用。
    【解决方案2】:

    你试过了吗?

    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    

    其他方式请查看How to Set the Look and Feel。那里提到了很多示例代码。

    【讨论】:

    • 我试过了,但问题仍然存在,在 eclipse 中构建和运行时工作正常,但在 netbeans 中构建和运行时不出现...
    猜你喜欢
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    相关资源
    最近更新 更多