0
private Popup popupProgressIndicator;
public void showProgressIndicator(ScreensController myController) {
if (popupProgressIndicator == null) {
ProgressIndicator indicator = new ProgressIndicator(-1.0);
indicator.setPrefHeight(200);
indicator.setPrefWidth(200);
indicator.setLayoutX(0);
indicator.setLayoutY(0);
popupProgressIndicator = new Popup();
popupProgressIndicator.getContent().add(indicator);
}
if (!popupProgressIndicator.isShowing()) {
popupProgressIndicator.show(primaryStage);
popupProgressIndicator.centerOnScreen();
}
myController.setDisable(true);
}
public void hideProgressIndicator(ScreensController myController) {
if (popupProgressIndicator.isShowing())
popupProgressIndicator.hide();
myController.setDisable(false);
}
嗨我使用上面的代碼在javafx應用程序中創建進度指示器。 我想從數據庫加載數據或將數據保存到數據庫時顯示進度指示器。javafx db加載進度指示器
@FXML
private void addDesignationSelect() {
showProgressIndicator(myController);
Task<Void> task = new Task<Void>() {
@Override
protected Void call() throws Exception {
Platform.runLater(new Runnable() {
@Override
public void run() {
// doing some heavy db process
}
});
return null;
}
@Override
protected void succeeded() {
hideProgressIndicator(myController);
}
@Override
protected void failed() {
super.failed();
hideProgressIndicator(myController);
}
};
new Thread(task).start();
}
我已經使用任務來加載進度條,但它沒有顯示進度條。我做錯了什麼?