title: How do I center JavaFX controls
body: <p>More specifically, why are my JavaFX controls not being centered? Here are two screenshots, the first just after starting (I moved the window into a more visible spot but have not yet resized it), and the second is just after resizing it to show off my problem. Bonus points if you help me ensure it's properly sized (on all DPIs) when it first shows:</p>
  
  <p><img src="https://i.stack.imgur.com/KNfrV.png" alt="A small window with the title &quot;Checking&quot;, and only a small sliver of content, on top of its own code">
  <img src="https://i.stack.imgur.com/p5As7.png" alt="The same scene, but the window now shows the title &quot;Checking for Updates...&quot;, its content more apparent, where the components are centered, but not their content."></p>
  
  <p>Conveniently, the relevant code is included in those screenshots. If you still need it as text, here you go:</p>
  
  <pre class="lang-java prettyprint-override"><code>private void initJFXPanel(JFXPanel holder)
  {
      {
          {
              rootGrid = new GridPane();
              rootGrid.setAlignment(Pos.CENTER);
              rootGrid.setPadding(new Insets(16));
              rootGrid.setHgap(16);
              rootGrid.setVgap(8);
          }
  
          interior = holder.getScene();
          if (interior == null)
              holder.setScene(interior = new Scene(rootGrid));
          interior.setRoot(rootGrid);
  
      }
      {
          statusLabel = new Label("Checking for Updates...");
          statusLabel.setAlignment(Pos.CENTER);
          statusLabel.setTextAlignment(TextAlignment.CENTER);
          rootGrid.add(statusLabel, 0, 0);
      }
      {
          progressBar = new ProgressBar();
          progressBar.setProgress(-1);
          progressBar.setPrefWidth(Constants.MAX_WIN_BOUNDS.width / 5d); // 1/5 the width of the screen
          rootGrid.add(progressBar, 0, 1);
      }
      {
          downloadButton = new Button("Get it!");
          downloadButton.setAlignment(Pos.CENTER);
          rootGrid.add(downloadButton, 0, 2);
      }
      holder.setMinimumSize(new Dimension((int)(rootGrid.getPrefWidth() + .5), (int)(rootGrid.getPrefHeight() + .5)));
      setMinimumSize(holder.getMinimumSize());
  }
  </code></pre>