如何在JavaFX中设置WebView? [英] How to setup webview in javafx?

查看:313
本文介绍了如何在JavaFX中设置WebView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@FXML
void openCaptchaSolver(MouseEvent event) {
    Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow();
    Stage secondaryStage = new Stage();
    WebView web = new WebView();
    WebEngine engine = web.getEngine();
    engine.load("https://www.google.com");
    VBox root = new VBox();
    root.getChildren().addAll(web);
    secondaryStage.setScene(new Scene(root, 500, 575));
    secondaryStage.setTitle("Secondary Stage");
    secondaryStage.show();
}

我正在尝试JavaFX中的WebView入门,但是当尝试打开一个WebFX时,我收到以下所示的错误,我该如何解决此问题?

I'm trying to get started with WebView's in JavaFX but when trying to open one I'm receiving the errors shown below, how would I go about fixing this issue?

Caused by: java.lang.IllegalAccessError: superclass access check failed: class com.sun.javafx.sg.prism.web.NGWebView (in unnamed module @0x6b0c2d26) cannot access class com.sun.javafx.sg.prism.NGGroup (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.sg.prism to unnamed module @0x6b0c2d26

推荐答案

在尝试运行WebView时遇到任何错误时,请确保您的VM选项包含模块javafx.web.

When getting any errors trying to run WebView make sure your VM options contain the module javafx.web.

VM选项:--module-path C:\path\to\javafx\openjfx-13.0.1_windows-x64_bin-sdk\javafx-sdk-13.0.1\lib --add-modules javafx.controls,javafx.fxml,javafx.web

在IntelliJ中,您可以通过转到IDE右上角的编辑配置"按钮来访问VM选项.

In IntelliJ you can access the VM options by going to the "Edit Configurations" button in the top right of the IDE

这篇关于如何在JavaFX中设置WebView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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