我正在开发与 JavaFX 控件混合的 Swing 应用程序。
我创建了一个 JavaFX 控件(WebView
) 浏览 HTML 文件。但我想要
要知道,如何在 Swing 的容器上添加此 Web 视图控件JFrame
?
鉴于已经存在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/");
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)