Ano, vím o FillTransition. Šlo mi pouze o znázornění mého problému. Každopádně perfektní. Už to funguje. Děkuji
Výsledný kód teda vypadá:
import java.util.stream.IntStream;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;
public class Example extends javafx.application.Application {
@Override
public void start(Stage primaryStage) {
var rectangle = new Rectangle(200, 200, Color.BLACK);
var list_of_color = new Color[]{Color.PINK, Color.MAGENTA, Color.RED, Color.GREEN, Color.YELLOW, Color.TURQUOISE, Color.BLUE, Color.ORANGE};
var timeline = new Timeline();
rectangle.setOnMouseClicked((t) -> {
IntStream
.range(0, list_of_color.length)
.mapToObj(
index -> new KeyFrame(
Duration.millis(index * 400), event -> {
rectangle.setFill(list_of_color[index]);
}
)
)
.forEach(timeline.getKeyFrames()::add);
timeline.play();
});
primaryStage.setTitle("Example!");
primaryStage.setScene(new Scene(new Pane(rectangle)));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}