JavaFX Translate effect

Description

JavaFX Translate effect


import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {
    Application.launch(args);/*from   w  w  w .  j a  v  a  2s .  c  o m*/
  }

  @Override
  public void start(Stage stage) {
    Rectangle rect1 = new Rectangle(100, 50, Color.LIGHTGRAY);
    rect1.setStroke(Color.BLACK);

    Rectangle rect2 = new Rectangle(100, 50, Color.YELLOW);
    rect2.setStroke(Color.BLACK);

    Translate translate = new Translate(50, 10);

    rect2.getTransforms().addAll(translate);

    Pane root = new Pane(rect1, rect2);
    root.setPrefSize(200, 100);
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Applying Transformations");
    stage.show();
  }
}



PreviousNext

Related