title: Get screen coordinates of a node in javaFX 8
body: <p>I am developing a JavaFX application on Windows 8.1 64bit with 4GB of RAM with JDK version 8u45 64bit.</p>
  
  <p>I want to capture part of the screen using <code>Robot</code> but the problem is that I can't get the screen coordinates of the anchor pane that I want to capture and I don't want to use <code>snapshot</code> because the output quality is bad. Here is my code.</p>
  
  <p>I have seen the question in this link
  <a href="https://stackoverflow.com/questions/1531538/getting-the-global-coordinate-of-a-node-in-javafx">Getting the global coordinate of a Node in JavaFX</a>
  and this one
  <a href="https://stackoverflow.com/questions/31148690/get-real-position-of-a-node-in-javafx">get real position of a node in javaFX</a>
  and I tried every answer but nothing is working, the image shows different parts of the screen.</p>
  
  <pre><code>private void capturePane() {
      try {
          Bounds bounds = pane.getLayoutBounds();
          Point2D coordinates = pane.localToScene(bounds.getMinX(), bounds.getMinY());
          int X = (int) coordinates.getX();
          int Y = (int) coordinates.getY();
          int width = (int) pane.getWidth();
          int height = (int) pane.getHeight();
          Rectangle screenRect = new Rectangle(X, Y, width, height);
          BufferedImage capture = new Robot().createScreenCapture(screenRect);
          ImageIO.write(capture, "png", new File("image.png"));
      } catch (IOException | AWTException ex) {
          ex.printStackTrace();
      }
  }
  </code></pre>