Add WebView control on Swing JFrame

I am working on Swing application mixed with JavaFX control.

I have created a JavaFX control (WebView) to browse HTML files. But I want to know, how can I add this web view control on the container of a Swing JFrame?

Answers


Given an already existing jFrame, the following code adds a new WebView and loads a URL:

// You should execute this part on the Event Dispatch Thread
// because it modifies a Swing component 
JFXPanel jfxPanel = new JFXPanel();
jFrame.add(jfxPanel);

// Creation of scene and future interactions with JFXPanel
// should take place on the JavaFX Application Thread
Platform.runLater(() -> {
    WebView webView = new WebView();
    jfxPanel.setScene(new Scene(webView));
    webView.getEngine().load("http://www.stackoverflow.com/");
});

JFXPanel allows you to embed JavaFX within your Swing application.


Need Your Help

How similar are Boost filesystem and the standard C++ filesystem libraries?

c++ c++11 c++17 c++-standard-library boost-filesystem

I need a filesystem library for use with a C++11-capable compiler or a C++14-capable one - so it can't be be from C++17.

How to use transactions with dapper.net?

c# transactions dapper

I would like to run multiple insert statements on multiple tables. I am using dapper.net. I don't see any way to handle transactions with dapper.net.