Q:

Javafx Shortening a line on 1 side

I was trying to animate shortening a line by one side on javafx. I want starting point to be stay at where it is and ending point to get closer to starting point. I couldn't find a proper transition for it. So I used this piece of code:
        PathTransition pt = new PathTransition(Duration.millis(1000), new Line(x1*3/4, y, x1, y), line);
        pt.play();
        ScaleTransition stBig = new ScaleTransition();
        stBig.setNode(line);
        stBig.setFromX(2);
        stBig.setToX(0.25);
        stBig.setDuration(new Duration(1000));
        stBig.play();

But it didn't work. Can I do it in one type of transition or is there any way out ?

A:

Since the line is horizontal, you only need to change the endX property, which you can do with a simple Timeline:
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;
import javafx.util.Duration;

public class LineAnimation extends Application {

    @Override
    public void start(Stage primaryStage) {
        Line line = new Line(100, 200, 300, 200);

        Timeline animation = new Timeline(
            new KeyFrame(Duration.seconds(1), new KeyValue(line.endXProperty(), 100))    
        );
        animation.setCycleCount(Animation.INDEFINITE);
        animation.play();

        Pane root = new Pane(line);
        Scene scene = new Scene(root, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Even if you need to animate both the endX and endY properties, it is not much more complicated:
    Line line = new Line(100, 100, 300, 300);

    Timeline animation = new Timeline(
        new KeyFrame(Duration.seconds(1), 
                new KeyValue(line.endXProperty(), 100),
                new KeyValue(line.endYProperty(), 100))    
    );

