VGR, но этот код показывает, что временная шкала все еще может использоваться в другом потоке:
public class FillingTimeLine extends Application {
private LongProperty lp = new SimpleLongProperty(0);
private Timeline timeline = new Timeline();
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
System.out.println("\nSTARTING THREAD: " + Thread.currentThread().getName());
StackPane spane = new StackPane();
ProgressBar pb = new ProgressBar(0);
pb.setMinSize(160, 21.5);
pb.setMaxSize(160, 21.5);
pb.setPrefSize(160, 21.5);
pb.progressProperty()
.bind(lp.divide(10000 * 1.0));
pb.setStyle("-fx-base:darkgray;-fx-accent:red;");
spane.getChildren().add(pb);
Scene scene = new Scene(spane, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
startFilling();
stopFilling();
}
public void startFilling() throws InterruptedException {
new Thread(() -> {
System.out.println("\nSTARTING THREAD: " + Thread.currentThread().getName());
timeline = new Timeline(new KeyFrame(Duration.seconds(0), new KeyValue(lp, 0)),
new KeyFrame(Duration.seconds(10), new KeyValue(lp, 10000)));
if (Thread.currentThread().isInterrupted()) {
System.out.println("\n THR WAS INTERRUPTED!");
return;
}
timeline.play();
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
System.out.println("\n THR WAS INTERRUPTED!");
return;
}
}).start();
}
public void stopFilling() {
new Thread(() -> {
System.out.println("\nSTOPPING THREAD: " + Thread.currentThread().getName());
try {
Thread.sleep(4000);
timeline.stop();
} catch (InterruptedException e) {
return;
}
}).start();
}
public static void main(String[] args) {
launch(args);
}
}
Или я ошибаюсь?