在Swing JFrame上添加WebView控件

我正在研究与JavaFX控件混合的Swing应用程序。

我创建了一个JavaFX控件( WebView )来浏览HTML文件。 但我想知道,如何在Swing JFrame的容器上添加此Web视图控件?

给定已存在的jFrame ,以下代码添加新的WebView并加载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允许您在Swing应用程序中嵌入JavaFX。