gpt4 book ai didi

css - javafx 进度条动态绑定(bind)颜色以进行进度

转载 作者:太空宇宙 更新时间:2023-11-04 01:17:26 25 4
gpt4 key购买 nike

所以我需要为 ProgressIndicator/Bar 创建一个计时器。我用时间轴制作了“动画”,但我不知道如何更改 ProgressIndicator 的颜色?

private ProgressIndicator progress = new ProgressIndicator();
private Timeline timeline = new Timeline();

public void doTime(int sec){

Timeline time = new Timeline(

new KeyFrame(
Duration.ZERO,
new KeyValue(progress.progressProperty(), 1)
),
new KeyFrame(
Duration.seconds(sec),
new KeyValue(progress.progressProperty(), 0)
)
);
time.setCycleCount(1);
time.play();
}

如果进度为 0.33,我希望颜色为红色。我没有找到任何进度的监听器。

if (progress.getProgress() <= 0.33) {
progress.setStyle("-fx-progress-color: red;");

}

您知道如何实现这一点吗?

最佳答案

您可以向进度指示器的 progressProperty() 添加一个监听器:

progress.progressProperty().addListener((obs, oldProgress, newProgress) -> {
if (newProgress <= 0.33) {
progress.setStyle("-fx-progress-color: red;");

} else {
progress.setStyle("");
}
});

关于css - javafx 进度条动态绑定(bind)颜色以进行进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49847836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com