title: JavaFX center stage on screen
body: <p>I want to center a stage on the screen.<br>
  This is what I've tried:</p>
  
  <pre><code>public class Test extends Application
  {
     @Override
     public void start(final Stage primaryStage)
     {
         Button btn = new Button();
         btn.setText("Say 'Hello World'");
         btn.setOnAction(new EventHandler&lt;ActionEvent&gt;()
         {
            @Override
            public void handle(ActionEvent event)
            {
              System.out.println("Hello World!");
            }
          });
          StackPane root = new StackPane();
          root.getChildren().add(btn);
          Scene scene = new Scene(root, 300, 250);
          primaryStage.setTitle("Hello World!");
          primaryStage.setScene(scene);
          primaryStage.centerOnScreen();
          primaryStage.show();
     }
  
     public static void main(String[] args)
     {
         launch(args);
     }
  }
  </code></pre>
  
  <p>After calling centerOnScreen() the stage is too high. It does not seem to work properly. Do I need to calulate the x and y pos myself? Or how do I use this function correctly?</p>