JavaFx loading 数据加载中效果

JavaFx loading

请求网络时显示loading(数据加载中),请求结束后loading消失。代码来于:https://blog.csdn.net/loongshawn/article/details/52996382,有改动。

import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.Background;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class ProgressFrom {
    private Stage dialogStage;
    private ProgressIndicator progressIndicator;

    public ProgressFrom(Stage primaryStage) {
        dialogStage = new Stage();
        progressIndicator = new ProgressIndicator();
        // 窗口父子关系
        dialogStage.initOwner(primaryStage);
        dialogStage.initStyle(StageStyle.UNDECORATED);
        dialogStage.initStyle(StageStyle.TRANSPARENT);
        dialogStage.initModality(Modality.APPLICATION_MODAL);
        // progress bar
        Label label = new Label("数据加载中, 请稍后...");
        label.setTextFill(Color.BLUE);
        progressIndicator.setProgress(-1F);
        VBox vBox = new VBox();
        vBox.setSpacing(10);
        vBox.setBackground(Background.EMPTY);
        vBox.getChildren().addAll(progressIndicator,label);
        Scene scene = new Scene(vBox);
        scene.setFill(null);
        dialogStage.setScene(scene);
    }

    public void activateProgressBar() {
        dialogStage.show();
    }

    public Stage getDialogStage(){
        return dialogStage;
    }

    public void cancelProgressBar() {
        dialogStage.close();
    }
}

效果如下图所示:
JavaFx loading 数据加载中效果_第1张图片

问题:
此loading出现后,界面就失去控制了,直到调用loading的cancle方法,用户在这中间不能取消,退出都不能。还没有解决办法???

你可能感兴趣的:(JavaFx)