, 당신이 필요로하는 모든입니다
ProgressBar progress = new ProgressBar();
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(progress.progressProperty(), 0)),
new KeyFrame(Duration.minutes(1), e-> {
// do anything you need here on completion...
System.out.println("Minute over");
}, new KeyValue(progress.progressProperty(), 1))
);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
그 진행 막대에 대해 "아날로그"효과를 생성합니다. 즉, 매 초마다 점진적으로 증가하지는 않지만 매분마다 부드럽게 증가합니다. 당신이 정말로 점진적으로 각 초를 늘리려면
, (초)을 대표하는 IntegerProperty
을 사용하고, 여기에 진행률 표시 줄의 진행 속성을 바인딩 :
ProgressBar progress = new ProgressBar();
IntegerProperty seconds = new SimpleIntegerProperty();
progress.progressProperty().bind(seconds.divide(60.0));
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(seconds, 0)),
new KeyFrame(Duration.minutes(1), e-> {
// do anything you need here on completion...
System.out.println("Minute over");
}, new KeyValue(seconds, 60))
);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
여기에서의 포인트 IntegerProperty
이 보간 것입니다 0에서 60 사이이지만 정수 값만 허용합니다 (즉 보간 값을 int
으로 자릅니다).
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.util.Duration;
public class OneMinuteTimer extends Application {
@Override
public void start(Stage primaryStage) {
ProgressBar progress = new ProgressBar();
progress.setMinWidth(200);
progress.setMaxWidth(Double.MAX_VALUE);
IntegerProperty seconds = new SimpleIntegerProperty();
progress.progressProperty().bind(seconds.divide(60.0));
Timeline timeline = new Timeline(
new KeyFrame(Duration.ZERO, new KeyValue(seconds, 0)),
new KeyFrame(Duration.minutes(1), e-> {
// do anything you need here on completion...
System.out.println("Minute over");
}, new KeyValue(seconds, 60))
);
timeline.setCycleCount(Animation.INDEFINITE);
timeline.play();
StackPane root = new StackPane(progress);
root.setPadding(new Insets(20));
primaryStage.setScene(new Scene(root));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
: 여기
번째 버전으로 SSCCE 인