如何显示进度栏0的值

时间:2018-08-20 10:22:45

标签: javafx progress-bar

我希望在获得结果时显示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;
    }
};

感谢您发表评论

1 个答案:

答案 0 :(得分:0)

绑定到progress属性乘以progress而不是绑定到任务的0.8属性。这样,您可以将任务进度的[0, 1]范围转换为[0, 0.8]范围:

progress.progressProperty().bind(task.progressProperty().multiply(0.8));