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

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

问题描述

我正在使用JavaFX控制混合Swing应用程序。

I am working on Swing application mixed with JavaFX control.

我创建了一个JavaFX的控制(的WebView )浏览HTML文件。但我想要
     要知道,我怎么能一个Swing的容器上添加此网页视图控件的JFrame

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 ,以下code增加了一个新的的WebView 并加载网址:

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天全站免登陆