如何关闭webview从关闭运行?了JavaFx

时间:2016-07-21 14:29:47

标签: java 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 个答案:

答案 0 :(得分:1)

在stop方法中退出PlatForm像这样:

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();
    }
}