Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8219080

Control with a maxHeight reserves preferredHeight in a baselined HBox

XMLWordPrintable

    • x86_64
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 7 Professional
      Open JDK 11+28

      A DESCRIPTION OF THE PROBLEM :
      If there is a HBox with the Alignment BASELINE_LEFT and inside of the box is a control like a TextArea with a set max height (smaller than the common preferredHeight) the HBox takes more space than really needed.

      You can see it if the box is inside of a VBox with a label under it. The label isn't directly under the HBox. There is some space between them

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the example code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No Space between TextArea and Label
      ACTUAL -
      The TextArea has the given maxHeight but under the TextArea is an empty space until the label is rendered.

      In Region.getMaxAreaHeight(List<Node> children, Callback<Node,Insets> childMargins, double childWidths[], VPos valignment, boolean minimum) the heigth of all children will be calculated. But only the prefHeight is taken into account even though the max height is set and smaller than the preferred height.
      That is the reason why the VBox reserves a bigger height for the HBox

      ---------- BEGIN SOURCE ----------
      TextArea area = new TextArea("Text\nText\nText");
      area.setMaxHeight(50);

      Label label = new Label("Hello");
      HBox box = new HBox(label, area);
      box.setAlignment(Pos.BASELINE_LEFT);

      VBox vbox = new VBox(box, new Label("a Label"));

      Scene scene = new Scene(vbox, SCENE_WIDTH, SCENE_HEIGHT, Color.WHITE);
      primaryStage.setScene(scene);
      primaryStage.show();
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Change the alignment to not a BASELINE, but it is not the desired result.

      FREQUENCY : always


            aghaisas Ajit Ghaisas
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: