所以我试图将我的 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/