title: Moving a Rectangle to the position where a mouse click happen
body: <p>I am trying to create a project where the user clicks on the screen and then a rectangle will move to the position where the clicked occurred. My intention was to get the center of the rectangle to move the exact location of the click but my code only moves the rectangle into the general area of where the click occurred. My question is how do I get the center of the rectangle to move the exact location of where a mouse click occurs? </p>
  
  <pre><code>public void start(Stage primaryStage) {
  
      BorderPane root = new BorderPane();
      Scene scene = new Scene(root,400,400);
  
      Rectangle rec = new Rectangle(50,50,50,50);
      rec.setLayoutX(200);
      rec.setLayoutY(200);
  
      TranslateTransition transition = new TranslateTransition(Duration.seconds(0.50), rec);
      transition.setOnFinished(new EventHandler&lt;ActionEvent&gt;() {
          @Override public void handle(ActionEvent t) {
              rec.setLayoutX(rec.getTranslateX() + rec.getLayoutX());
              rec.setLayoutY(rec.getTranslateY() + rec.getLayoutY());
              rec.setTranslateX(0);
              rec.setTranslateY(0);
          }
      });
  
      scene.setOnMousePressed(e-&gt;{
          transition.setToX(e.getSceneX() - rec.getLayoutX());
          transition.setToY(e.getSceneY() - rec.getLayoutY());
          transition.playFromStart();
      });
  
      root.getChildren().add(rec);
  
      primaryStage.setScene(scene);
      primaryStage.show();
  
  }
  </code></pre>