在打开jar文件时,更改JAVA中的外观并不能正常工作

问题描述 投票:0回答:1

所以我试图将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感觉,并且它起作用了!我想这是问题所在。

java windows swing user-interface look-and-feel
1个回答
2
投票

我的项目有三个JFrame,在将所有三个JFrame都更改为Windows外观后,我仅将两个JFrame更改为Windows外观,此问题已解决。

© www.soinside.com 2019 - 2024. All rights reserved.