java - 打开 jar 文件时,更改 JAVA 中的外观和感觉不起作用

标签 java windows swing user-interface look-and-feel

所以我试图将我的 java gui 的外观和感觉从 nimbus 更改为 windows。当我在 netbeans 上启动程序时它可以工作,但当我构建它并启动 jar 文件时它不起作用。 我使用的是 Windows 10

我的代码:

public static void main(String args[]) {
        /* 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("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
       MainFrm f = new MainFrm();
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                f.setVisible(true);

            }
        });
    }

谢谢!

编辑:我的主要项目,其中有三种形式。我只将两个更改为 Windows 感觉,我将所有三个更改为 Windows 感觉并且它起作用了!我想这就是问题所在。

最佳答案

我的项目有三个 JFrame,我只将两个 JFrame 更改为窗口外观,将所有三个 JFrame 更改为窗口外观后,问题得到解决。

关于java - 打开 jar 文件时,更改 JAVA 中的外观和感觉不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59025752/

相关文章:

java - SolrJ 中缺少强制唯一键字段错误

java - Swing TCP 客户端终止与服务器的连接,但随后可以重新连接

windows - 查找具有给定存储库主机名的 Subversion 工作副本

java - .drawLine 未绘制到 JTabbedPane (Java) 上

java - 在 java swing 中自定义默认的 html 链接颜色

Java - JList , getSelectedValues 方法的困难

java - Jackson 序列化类文字

java - 如何根据输入长度更改 DecimalFormat 行为?

c++ - C/C++ iTunes API 在哪里? (不是 COM!)

windows - 是否可以在上下文/线程之间共享 opengl 帧缓冲区对象?