java - 如何调用 JFrame 并设置外观?

标签 java swing jframe look-and-feel

我的程序从一个调用 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/

相关文章:

java - 用户定义的 CORBA 异常在编译后给我错误

java - SwingUtilities.invokeLater()

java - 使用自定义 X509KeyManager 时,Java 无法为 SSL 握手确定匹配的密码套件

java - 方法的final局部变量 'avoid repeat invocations'怎么办?

java - 将 JRadioSelection 传递给 ActionLIstener 类

java - 构造函数调用或 JFrame 的问题

Java Swing 计时器的速度不同

java - 使用 JFreeChart 在 Netbeans 中编译错误

java - 从另一个类中处理 JFrame

java - JPanel 在 JFrame 中不可见