[英]How to call a JFrame and set look and feel?
My program starts with a class that calls out a JFrame
. 我的程序从调用JFrame
的类开始。 On the frame, I have the LaF set up correctly, but when the main class calls it, the LaF doesn't take. 在框架上,我正确设置了LaF,但是当主类调用它时,LaF不会显示。
If I start only the file, it works. 如果我仅启动文件,则它可以工作。 If I start the project, it doesn't. 如果我启动项目,则不会。
The code below is under the main method on the frame. 下面的代码在框架的主要方法下。
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);
}
If the main class calls it: 如果主类调用它:
TelaTur tela = new TelaTur();
tela.setVisible(true);
It doesn't take. 不用 Opening just the file (on Netbeans Shift + F6) takes the LaF. 仅打开文件(在Netbeans Shift + F6上)将使用LaF。
I´m looking for the answer to: 我在寻找答案:
How to set the look and feel from the main class? 如何从主要班级设置外观?
This answer is based on what @GilianJoosen wrote on comments. 该答案基于@GilianJoosen在评论中写的内容。
I created a method named setLookAndFeel() and called it before the initComponents() method on the constructor. 我创建了一个名为setLookAndFeel()的方法,并在构造函数的initComponents()方法之前对其进行了调用。
Thanks for the answers. 感谢您的回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.