在Swing JFrame上添加WebView控件

ade*_*esh 16 java swing javafx awt javafx-2

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

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

hee*_*nee 25

鉴于已存在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/");
});
Run Code Online (Sandbox Code Playgroud)


小智 5

JFXPanel允许您在 Swing 应用程序中嵌入 JavaFX。