import javafx.animation.Interpolator; import javafx.animation.Timeline; import javafx.animation.TranslateTransition; import javafx.animation.TranslateTransitionBuilder; import javafx.application.Application; import javafx.beans.property.DoubleProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.text.TextBuilder; import javafx.stage.Stage; import javafx.util.Duration; /** * * @author cdea */ public class TranslateTest extends Application { /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { primaryStage.setTitle("Testing the binding of fromXProperty"); Group root = new Group(); Scene scene = new Scene(root, 300, 250, Color.BLACK); Text news = TextBuilder.create() .text("JavaFX 2.0 hello there this is a news ticker | :)") .translateY(18) .fill(Color.WHITE) .build(); final TranslateTransition ticker = TranslateTransitionBuilder.create() .node(news) .duration(Duration.millis(15000)) .fromY(19) .interpolator(Interpolator.LINEAR) .cycleCount(Timeline.INDEFINITE) .build(); DoubleProperty fromXProperty = new SimpleDoubleProperty(); fromXProperty.bind(scene.widthProperty()); fromXProperty.addListener(new ChangeListener() { public void changed(ObservableValue observable, Number oldValue, Number newValue) { System.out.println("new fromXProperty: " + newValue); } }); ticker.fromXProperty().bind(fromXProperty); DoubleProperty toXProperty = new SimpleDoubleProperty(); toXProperty.bind(scene.widthProperty().subtract(scene.widthProperty().add(scene.widthProperty()))); toXProperty.addListener(new ChangeListener() { public void changed(ObservableValue observable, Number oldValue, Number newValue) { System.out.println("new toXProperty: " + newValue); } }); ticker.toXProperty().bind(toXProperty); ticker.play(); root.getChildren().add(news); primaryStage.setScene(scene); primaryStage.show(); } }