Skip to content
Advertisement

JavaFX WebView in Java Swing Project

i try to use the WebView in my java project, in my code is:

JavaScript

but the this thown a exception

JavaScript

And yes, this is not a JavaFx application.

Advertisement

Answer

You can embed JavaFX content into a Swing application using JFXPanel. Note that for this to work correctly, you have to be careful to create and access the Swing content on the AWT event dispatch thread, and create and access the JavaFX content on the FX Application Thread, so you will need to carefully manage code using SwingUtilities.invokeLater(...) and Platform.runLater(...). (See the documentation for more details.)

Creating a JFXPanel starts the FX Application toolkit, if it is not already started.

Here is a simple example of embedding a JavaFX WebView into a Swing application:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement