问题
@FXML
void openCaptchaSolver(MouseEvent event) {
Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow();
Stage secondaryStage = new Stage();
secondaryStage.initOwner(primaryStage);
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("Captcha Solver");
secondaryStage.initModality(Modality.NONE);
secondaryStage.initOwner(secondaryStage.getOwner());
secondaryStage.setResizable(false);
secondaryStage.show();
}
This is the code I have which I have found online for setting up a basic pop up with WebView however when I debug it a get a load of errors, one of which being;
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
if anyone knows how to fix this it would be much appreciated if you need any more code or details just ask
回答1:
When getting any errors trying to run WebView make sure your VM options contain the module javafx.web.
VM Options: --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
In IntelliJ you can access the VM options by going to the "Edit Configurations" button in the top right of the IDE
来源:https://stackoverflow.com/questions/59342356/how-to-setup-webview-in-javafx