title: JavaFX screen resolution scaling
body: <p>I have been searching for a method to do this, but I only found <a href="https://stackoverflow.com/questions/32453173/javafx-scale-elements-to-screen-resolution">This question without answers</a>.</p>
  
  <p>I am developing in a 1366x768 laptop, I use JavaFX to create a GUI (I am sorry, but I can't post the code, it's basically an AnchorPane containing a couple GridPanes, which contain more GridPanes, which contain Labels, TextFields and a couple Charts). </p>
  
  <p>The problem comes when I load the project on another resolution (1920x1080 or 1600x900).</p>
  
  <p>I am using <code>stage.setMaximized(true);</code>, but this only Scales the background, the stage itself, so all the elements and containers (Panels, Labels, TextFields.....) remain the same size as with the 1366x768 resolution, making the GUI "not fit" at resolutions that are not exactly 1366x768.</p>
  
  <p>I hope I explained my problem well enough, my english is far from perfect. </p>
  
  <p>Does anyone have any suggestion on how to make elements scale with stage resolution?</p>
  
  <p>(I need the software to be maximised or full screen in every monitor, so making a fixed resolution (1366x768, for example) doesn't seem like a good solution).</p>
  
  <p>Thank you all.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I just created a little example. It's a 2x1 GridPane inside the default JavaFX AnchorPane, I added two example Buttons to the grid pane. </p>
  
  <pre><code>&lt;AnchorPane minHeight="-Infinity" minWidth="-Infinity" prefHeight="300.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" &gt;
  &lt;children&gt;
      &lt;GridPane prefHeight="300.0" prefWidth="400.0"&gt;
          &lt;columnConstraints&gt;
              &lt;ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /&gt;
          &lt;/columnConstraints&gt;
          &lt;rowConstraints&gt;
              &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
              &lt;RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /&gt;
          &lt;/rowConstraints&gt;
          &lt;children&gt;
              &lt;Button fx:id="example1" mnemonicParsing="false" text="Example 2" GridPane.halignment="CENTER" GridPane.valignment="CENTER" /&gt;
              &lt;Button fx:id="example2" mnemonicParsing="false" text="Example 2" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" /&gt;
          &lt;/children&gt;
      &lt;/GridPane&gt;
  &lt;/children&gt;
  </code></pre>
  
  <p></p>
  
  <p>This code looks nice in a 400x300 screen (Too little, I know, it's just an example), when I scale it to 1366x768 (Not real full screen, just <code>stage.setMaximized(true);</code>), the GridPane does not scale, only the Stage itself, so I have a full screen background, with a 400x300 Pane (With its tiny Buttons) on the top-left corner of my screen. </p>
  
  <p>TL;DR: The example code the buttons stay in the top-left corner of the screen, and the rest is just an empty space when I scale up resolution.</p>
  
  <p><strong>Update 2;</strong> Forgot the Java Code.</p>
  
  <pre><code>Parent root = FXMLLoader.load(getClass().getResource("UI.fxml"));
  Scene scene = new Scene(root, java.awt.Toolkit.getDefaultToolkit().getScreenSize().width,
              java.awt.Toolkit.getDefaultToolkit().getScreenSize().height);
  stage = new Stage();
  stage.setMaximized(false);
  stage.setScene(scene);
  stage.setTitle("Example Menu");
  stage.show();
  </code></pre>