title: JavaFX VBox Resizing
body: <p>I'm creating pop-up confirmation messages in my JavaFX-based game, and trying to figure out how layout works.  My PopUp class extends the StackPane and its constructor looks like so:</p>
  
  <pre><code>public PopUp (String str)
  {
      super();
      Color dark = Color.rgb(0, 0, 0, 0.35);
      setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
      setPrefSize(Double.MAX_VALUE, Double.MAX_VALUE);
      FXUtil.backgroundColor(dark, this);
  
      Text displayText = new Text(str);
      displayText.setFont(FontFactory.general(18.0));
      displayText.setFill(Color.WHITE);
      displayText.setWrappingWidth(560.0);
  
      buttonBox = new HBox(20.0);
      buttonBox.setAlignment(Pos.CENTER);
      FXUtil.backgroundColor(Color.GREY, buttonBox);
  
      VBox arrangement = new VBox(20.0, displayText, buttonBox);
      arrangement.setAlignment(Pos.CENTER);
      arrangement.setMaxWidth(600.0);
      FXUtil.backgroundColor(Color.RED, arrangement);
  
      getChildren().add(arrangement);
  }
  </code></pre>
  
  <p>(The FXUtil class is a convenience for setting background colors, and FontFactory is what it sounds like)</p>
  
  <p>A couple of buttons get added later, but I am surprised to see that the VBox, arrangement, uses the full vertical space even though its preferred height is the combined height of its children (plus insets, etc., as per the doc).  Basically, it's a tall red bar that spans the height of the window.</p>
  
  <p>Is there a way to make it use its preferred height rather than its max height?  I'd like it just to be tall enough to fit its children.</p>