title: JavaFX - ScrollPane in Dialog alternating height
body: <p>i have a problem with JavaFX.<br/><br/>
  I want to put a ScrollPane in a Dialog and give the Scrollpane a max-height, no min-height or pref-height because it can be shorter.<br/><br/>
  Here is a simple example to demonstrate my problem.<br/>
  The Main class:</p>
  
  <pre><code>package application;
  
  import javafx.application.Application;
  import javafx.scene.Scene;
  import javafx.scene.control.Button;
  import javafx.scene.layout.StackPane;
  import javafx.stage.Stage;
  
  public class Main extends Application
  {
    @Override
    public void start(Stage primaryStage)
    {
      try
      {
        StackPane root = new StackPane();
        MyDialog dialog = new MyDialog();
        Button button = new Button("Test");
        button.setOnMousePressed(e -&gt; dialog.showAndWait());
        root.getChildren()
            .add(button);
        Scene scene = new Scene(root, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
    }
  
    public static void main(String[] args)
    {
      launch(args);
    }
  }
  </code></pre>
  
  <p>The dialog class:</p>
  
  <pre><code>package application;
  
  import javafx.scene.control.Button;
  import javafx.scene.control.ButtonBar.ButtonData;
  import javafx.scene.control.ButtonType;
  import javafx.scene.control.Dialog;
  import javafx.scene.control.DialogPane;
  import javafx.scene.control.ScrollPane;
  import javafx.scene.layout.VBox;
  import javafx.scene.text.Text;
  
  public class MyDialog extends Dialog&lt;ButtonType&gt;
  {
    public MyDialog()
    {
      super();
      DialogPane dialogPane = new DialogPane();
      VBox outer = new VBox();
      Button button = new Button("Test");
      setResult(new ButtonType("NO", ButtonData.LEFT));
      button.setOnMousePressed(e -&gt; close());
      VBox inner = new VBox();
      inner.getChildren()
          .add(new Text("Test 1"));
      inner.getChildren()
          .add(new Text("Test 2"));
      inner.getChildren()
          .add(new Text("Test 3"));
      inner.getChildren()
          .add(new Text("Test 4"));
      inner.getChildren()
          .add(new Text("Test 5"));
      ScrollPane scroll = new ScrollPane(inner);
      scroll.setMaxHeight(80);
      outer.getChildren()
          .addAll(button, scroll);
      dialogPane.setContent(outer);
      this.setDialogPane(dialogPane);
    }
  }
  </code></pre>
  
  <p>The concrete Problem is following.<br/>
  The dialog should look like this:<br/>
  <a href="https://i.stack.imgur.com/gl71v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gl71v.png" alt="enter image description here"></a></p>
  
  <p>But everey second time i open it, it looks like this:<br/>
  <a href="https://i.stack.imgur.com/2A5kT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2A5kT.png" alt="enter image description here"></a></p>
  
  <p>I can't figure out what's the problem. Hopefully anybody can tell me why this is not working.</p>