0

I have some code and when it executes, it throws a RuntimeException, saying:

 JXBrowser should only be constructed on the EDT

it is stemming from when I'm creating a JXbrowser component

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

What should I look for in fixing this error?

2 Answers2

0

JavaFX (OpenJFX) is not thread-safe.

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.

Apparently your app is starting other threads and then performing JavaFX work on them. 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. But you must study to learn those techniques.

See this tutorial and this one.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
0

JxBrowser dropped this requirement since version 7.

In JxBrowser 7, you can initialize Engine and Browser in any thread. These operations are heavy and it's better not to do them in 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.

Vladyslav Lubenskyi
  • 527
  • 1
  • 7
  • 17