Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8210238

Transition animations do not play backwards properly


    • Type: Bug
    • Status: In Progress
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 9, 10, openjfx11
    • Fix Version/s: openjfx14
    • Component/s: javafx
    • Labels:


      The docs for Animation#play [1] specify:

      To play an Animation backwards from the end:
      animation.setRate(negative rate);
      animation.jumpTo(overall duration of animation);

      But this does not play the same animation from the end.

      Consider an animation that translates a node from 0 to 10:
      Playing will translate the node from 0 to 10. Then doing the above will translate the node from 20 to 10, and not from 10 to 0.

      Additionally, pausing the animation, setting rate = -1 and playing causes the animation to jump to the end.

      [1] https://docs.oracle.com/javase/10/docs/api/javafx/animation/Animation.html#play()

      --- Reproducer code ---

      import javafx.animation.Animation;
      import javafx.animation.TranslateTransition;
      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.geometry.Orientation;
      import javafx.scene.Node;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.Separator;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Pane;
      import javafx.scene.layout.VBox;
      import javafx.scene.paint.Color;
      import javafx.scene.shape.Circle;
      import javafx.stage.Stage;
      import javafx.util.Duration;

      public class AnimTest extends Application {

          public void start(Stage stage) throws Exception {
              Circle circle = new Circle(5, Color.BLUE);
              var translateBy = new TranslateTransition(Duration.seconds(2), circle);
              VBox byPane = setup(translateBy, circle);
              byPane.getChildren().add(0, new Label("By"));

              Circle circle2 = new Circle(5, Color.BLUE);
              var translateTo = new TranslateTransition(Duration.seconds(2), circle2);
              VBox toPane = setup(translateTo, circle2);
              toPane.getChildren().add(0, new Label("To"));

              HBox root = new HBox(10, byPane, new Separator(Orientation.VERTICAL), toPane);
              root.setPadding(new Insets(10));
              stage.setScene(new Scene(root));

          private VBox setup(Animation translate, Node node) {
              Button play = new Button("Play");
              play.setOnAction(e -> translate.play());

              Button pause = new Button("Pause");
              pause.setOnAction(e -> translate.pause());

              Button stop = new Button("Stop");
              stop.setOnAction(e -> translate.stop());

              Button jumpToStart = new Button("Jump to start");
              jumpToStart.setOnAction(e -> translate.jumpTo("start"));

              Button jumpToEnd = new Button("Jump to end");
              jumpToEnd.setOnAction(e -> translate.jumpTo("end"));

              Button rateP1 = new Button("rate=1");
              rateP1.setOnAction(e -> translate.setRate(1));

              Button rateM1 = new Button("rate=-1");
              rateM1.setOnAction(e -> translate.setRate(-1));

              Pane pane = new Pane(node);
              pane.setPrefSize(400, 300);

              Label curTime = new Label();

              Label curRate = new Label();

              VBox controls = new VBox(5,
                      new HBox(5, play, pause, stop, curTime),
                      new HBox(5, jumpToStart, jumpToEnd),
                      new HBox(5, rateP1, rateM1, curRate));
              VBox root = new VBox(10, pane, controls);
              return root;

          public static void main(String[] args) {


          Issue Links



              • Assignee:
                nlisker Nir Lisker
                nlisker Nir Lisker
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: