简体   繁体   English

这个错误是什么意思 JXBrowser 应该只在 EDT 上构建

[英]What does this error mean JXBrowser should only be constructed on the EDT

I have some code and when it executes, it throws a RuntimeException, saying:我有一些代码,当它执行时,它会抛出一个 RuntimeException,说:

 JXBrowser should only be constructed on the EDT

it is stemming from when I'm creating a JXbrowser component它源于我创建 JXbrowser 组件时

browser = (JXBrowser) browserFactory.create(true, WebBrowserType.JX);

What should I look for in fixing this error?在修复此错误时我应该寻找什么?

JavaFX (OpenJFX) is not thread-safe. JavaFX (OpenJFX)不是线程安全的。

Like Swing , Vaadin , and most any other user-interface framework, you must limit all access to, and manipulation of, the widgets and other UI-related objects only from within the one thread dedicated to that framework.SwingVaadin和大多数其他用户界面框架一样,您必须限制对小部件和其他 UI 相关对象的所有访问和操作,只能在专用于该框架的一个线程内进行。

Apparently your app is starting other threads and then performing JavaFX work on them.显然您的应用程序正在启动其他线程,然后对它们执行 JavaFX 工作。 Never do this.永远不要这样做。

There are ways for you to perform lengthy tasks on background threads, and then upon completion post a request to the UI thread to update the UI widgets with the results.您可以通过多种方式在后台线程上执行冗长的任务,然后在完成后向 UI 线程发布请求以使用结果更新 UI 小部件。 But you must study to learn those techniques.但是您必须学习以学习这些技术。

See this tutorial and this one .请参阅本教程教程。

JxBrowser dropped this requirement since version 7. JxBrowser 从版本 7 开始放弃了这个要求。

In JxBrowser 7, you can initialize Engine and Browser in any thread.在 JxBrowser 7 中,您可以在任何线程中初始化EngineBrowser These operations are heavy and it's better not to do them in EDT.这些操作很繁重,最好不要在 EDT 中进行。

Once the browser is created, you will need to create BrowserView and add it to your interface inside of EDT, according to Swing rules.创建浏览器后,您需要根据 Swing 规则创建BrowserView并将其添加到 EDT 内的界面。

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

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