有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在关闭时关闭webview?JavaFx

 Platform.runLater(() -> {
            WebView wv = new WebView();
            final WebEngine engine = wv.getEngine();
            fxpanel.setScene(new Scene(wv));
            engine.setJavaScriptEnabled(true);
            engine.load(Url);
        };

当我关闭这个框架时,当这个WebView打开时,我可以看到它们在后台运行,所以我尝试在一个公共的void类中这样关闭它,但是它没有正确关闭,所以我怎么做呢

   public static void closeframe() {
    Platform.setImplicitExit(false);
    if (ClassName != null) {
        ClassName.frame.dispose();

        Platform.runLater(() -> {
            wv = new WebView();
            ClassName.wv.getEngine().reload();

            ClassName.wv = null;
            ClassName.frame = null;
        });

共 (1) 个答案

  1. # 1 楼答案

    在停止方法中退出平台,如下所示:

    public class Main extends Application {
    
        //Entry point to application
        public static void main(String[] args) {
            launch(args);
        }
    
        @Override
        public void start(Stage primaryStage) throws Exception {
            Parent authScene = (Parent) FXMLLoader.load(getClass().getResource("/View/Auth.fxml"));
            Scene scene = new Scene(authScene);
            primaryStage.setScene(scene);
            primaryStage.setResizable(false);
            primaryStage.setTitle("Green Project : Login Form");
            primaryStage.show();
    
        }
    
        @Override
        public void stop() {
            Platform.exit();
        }
    }