我希望在获得结果时显示80%的结果。(从0开始到myresult = 80)
但是我的进度条显示结果0到100(最大进度条)
@FXML
private ProgressBar progress;
@Override
public void initialize(URL url, ResourceBundle rb) {
double percent = 0.8;
progress.setProgress(percent);
progress.progressProperty().bind(task.progressProperty());
Thread th = new Thread(task);
th.start();
// TODOs
}
public Task<Void> task = new Task<Void>() {
@Override
public Void call() {
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.interrupted();
break;
}
System.out.println(i + 1);
updateProgress(i + 1, 10);
}
return null;
}
};
感谢您发表评论
答案 0 :(得分:0)
绑定到progress
属性乘以progress
而不是绑定到任务的0.8
属性。这样,您可以将任务进度的[0, 1]
范围转换为[0, 0.8]
范围:
progress.progressProperty().bind(task.progressProperty().multiply(0.8));