title: How to center a window properly in Java FX?
body: <p>Java FX provides Window.centerOnScreen() to - guess what - center a window on a screen. HOWEVER, the Java FX' definition of "center of a screen" seems to be at (0.5x;0.33y). I hoped this was a bug, but <a href="https://javafx-jira.kenai.com/browse/RT-40368" rel="noreferrer">I was told it's not</a>.</p>
  
  <p>Anyway. Has someone came up with a clean and easy solution on how to center a Window before displaying it? My first approach leads to flickering of the screen, since the window has to be displayed first, before it can be centered.</p>
  
  <pre><code>public static void centerOnScreen(Stage stage) {
    stage.centerOnScreen();
    stage.setY(stage.getY() * 3f / 2f);
  }
  </code></pre>
  
  <p><strong>Update</strong>:
  What I forgot to mention; I don't know the size of the window beforehand, so in order to center it manually I have to display it first - what causes it to flicker one time. So I'm looking for a solution to center it without displaying it first - like Java FX is able to do it, however the wrong way.</p>