简体   繁体   English

尝试实时更改GUI时,Swing GUI引发异常

[英]Swing GUI throws Exception while trying to change the GUI in real time

So i have a swing GUI where i change it's default look and feel based upon some input from another GUI Class using something like this: 因此,我有一个摆动的GUI,在其中我可以根据其他GUI类的一些输入,使用如下所示更改其默认外观:

javax.swing.UIManager.setLookAndFeel("newlook&feel");
SwingUtilities.updateComponentTreeUI(this);
pack();

This works fine, but however on the console i see everytime this is called an exception is thrown with message like: 这可以正常工作,但是在控制台上我每次都看到这样的异常,并抛出类似以下消息:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

and it refers to line numbers from classes which are internal Java classes. 它是指来自内部Java类的类的行号。 What could be the problem here or i am missing something. 这可能是问题所在,还是我错过了一些东西。

Just a point, SwingUtilities.isEventDispatchThread() returns false in this scenario. 只是一点,在这种情况下, SwingUtilities.isEventDispatchThread()返回false

Just a point, SwingUtilities.isEventDispatchThread() returns false in this scenario. 只是一点,在这种情况下,SwingUtilities.isEventDispatchThread()返回false。

Maybe that is the problem, have you tried invoking the L&F change inside the EDT Thread? 也许是问题所在,您是否尝试过在EDT线程中调用L&F更改?

    SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         javax.swing.UIManager.setLookAndFeel("newlook&feel");
         SwingUtilities.updateComponentTreeUI(OuterClassName.this);
         pack();
        }
      });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM