我的程序从一个调用 JFrame
的类开始。在框架上,我正确设置了 LaF,但是当主类调用它时,LaF 不执行。
如果我只启动该文件,它就可以工作。如果我启动这个项目,它就不会。
下面的代码位于框架的 main 方法下。
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TelaTur.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
如果主类调用它:
TelaTur tela = new TelaTur();
tela.setVisible(true);
这不需要。仅打开文件(在 Netbeans Shift + F6 上)需要 LaF。
我正在寻找以下问题的答案:
如何设置主类的外观?
最佳答案
这个答案是基于@GilianJoosen 在评论中所写的内容。
我创建了一个名为 setLookAndFeel() 的方法,并在构造函数的 initComponents() 方法之前调用它。
感谢您的回答。
关于java - 如何调用 JFrame 并设置外观?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32591980/