在 Swing JFrame 上添加 WebView 控件 [英] Add WebView control on Swing JFrame

查看:62
本文介绍了在 Swing JFrame 上添加 WebView 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on Swing application mixed with JavaFX control.

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

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?

推荐答案

给定一个已经存在的 jFrame,下面的代码添加一个新的 WebView 并加载一个 URL:

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/");
});

这篇关于在 Swing JFrame 上添加 WebView 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆