title: Is specifying JavaFX CSS borders on GridPane contents supposed to collapse the sizing?
body: <p>I was attempting to layout a JavaFX stage using a <code>GridPane</code> when I ran into the following problem. If I setup the grid with the appropriate constraints and add newly instantiated <code>StackPane</code>s to it, the default sizing of the scene, stage, and it's contents ensures that the contents are visible:</p>
  
  <p><a href="https://i.stack.imgur.com/vWxAN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vWxAN.png" alt="Without CSS"></a></p>
  
  <p>However, if I add a JavaFX CSS style specifying a border to the newly instantiated <code>StackPane</code> before adding it to the <code>GridPane</code>, then the default sizing of things seems to collapse complete:</p>
  
  <p><a href="https://i.stack.imgur.com/8IAzA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8IAzA.png" alt="With CSS"></a></p>
  
  <p>My code is as follows:</p>
  
  <pre><code>public static void main(final String[] args) {
      Platform.startup(() -&gt; {});
      Platform.runLater(() -&gt; {
  
          final GridPane gridPane = new GridPane();
          final Scene scene = new Scene(gridPane);
          final Stage stage = new Stage();
          stage.setScene(scene);
  
          final List&lt;StackPane&gt; panes = new ArrayList&lt;&gt;();
          for (int i = 0; i &lt; 4; i++) {
  
              // Create a new pane with a random background color for
              // illustration
              final StackPane p = createNewPane();
              panes.add(p);
  
              // The addition / removal of the following line affects the
              // layout.
              p.setStyle("-fx-border-width:2px;-fx-border-color:red");
          }
  
          for (int r = 0; r &lt; 2; r++) {
              final RowConstraints rc = new RowConstraints();
              rc.setPercentHeight(50);
              gridPane.getRowConstraints().add(rc);
          }
          for (int c = 0; c &lt; 2; c++) {
              final ColumnConstraints cc = new ColumnConstraints();
              cc.setPercentWidth(50);
              gridPane.getColumnConstraints().add(cc);
          }
  
          for (int r = 0, i = 0; r &lt; 2; r++) {
              for (int c = 0; c &lt; 2; c++) {
                  gridPane.add(panes.get(i++), c, r);
              }
          }
          stage.show();
      });
  }
  </code></pre>
  
  <p>Curiously, if I move the <code>stage.show()</code> to right after I set the Scene, then everything works fine even with the CSS.</p>
  
  <p><strong>Can anyone help me understand, one, whether this is the expected behavior, and two, why the execution order of the <code>stage.show()</code> makes a difference?</strong></p>
  
  <p>Thanks!</p>