Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>TranslateTransition</code> works with <code>translateX</code> property of the Node. Thus, if you positioned rectangles using <code>setLayout</code>, <code>relocate</code> or just constructor parameter TranslateTransition wouldn't work for you.</p> <p>You either need to start using <code>translateX</code> coordinates or use <code>Timeline</code> instead of <code>TranslateTransition</code>.</p> <p>You can read more about layout and translate in <a href="http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#layoutXProperty" rel="nofollow">JavaDoc for layout</a></p> <p>Here is translateX based swap example:</p> <pre><code>public void start(Stage primaryStage) { final Rectangle r1 = new Rectangle(50, 50, Color.RED); final Rectangle r2 = new Rectangle(50, 50, Color.BLUE); // note I use translate to position rectangles r1.setTranslateX(50); r2.setTranslateX(250); Button btn = new Button(); btn.setText("Move it"); btn.relocate(100, 100); btn.setOnAction(new EventHandler&lt;ActionEvent&gt;() { @Override public void handle(ActionEvent event) { double x1 = r1.getTranslateX(); double x2 = r2.getTranslateX(); TranslateTransition translateTransition = new TranslateTransition(); translateTransition.setNode(r1); translateTransition.setDuration(Duration.millis(1000)); translateTransition.setToX(x2); TranslateTransition translateTransition2 = new TranslateTransition(); translateTransition2.setNode(r2); translateTransition2.setDuration(Duration.millis(1000)); translateTransition2.setToX(x1); translateTransition2.play(); translateTransition.play(); } }); Pane root = new Pane(); root.getChildren().addAll(btn, r1, r2); Scene scene = new Scene(root, 400, 350); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload