简体   繁体   English

SwingUtilities.invokeLater…是否有一个invokeNow?

[英]SwingUtilities.invokeLater … is there an invokeNow?

I had a problem earlier where I was trying to add objects to my canvas but the SwingUtilities.invokeLater hadn't really done its job yet. 之前我有一个问题 ,尝试将对象添加到画布中,但是SwingUtilities.invokeLater尚未真正完成其工作。 I really need to be able to add things reliably to this JPanel but I keep running into this same error. 我确实需要能够可靠地向此JPanel添加内容,但是我一直遇到这个错误。 Is there a better alternative to the below code? 下面的代码还有更好的选择吗?

private void startNewGame() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            gameFrame = new InvadersGameFrame();
        }
    });
}

See SwingUtilities.invokeAndWait(Runnable) which: 请参阅SwingUtilities.invokeAndWait(Runnable) ,其中:

Causes doRun.run() to be executed synchronously on the AWT event dispatching thread. 使doRun.run()在AWT事件分配线程上同步执行。 This call blocks until all pending AWT events have been processed and (then) doRun.run() returns. 该调用将阻塞,直到处理doRun.run()所有未决的AWT事件,然后(然后) doRun.run()返回。 This method should be used when an application thread needs to update the GUI. 当应用程序线程需要更新GUI时,应使用此方法。

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

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