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

BorderPane does not respect maxWidth settings of direct childs



    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 7u6
    • javafx


      consider following test case:

      import javafx.application.Application;
      import javafx.geometry.Pos;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.layout.*;
      import javafx.scene.shape.Line;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      public class LayoutBoundsTest extends Application {
        public static void main(String[] args) { launch(args); }
        @Override public void start(Stage stage) throws Exception {
          BorderPane pane = new BorderPane();

          // define center pane.
          StackPane center = new StackPane();
          center.setStyle("-fx-background-color: coral;");
          Label someLabel = new Label(" Label Bounds Issue Test");
          Line line = new Line(0,0,0,500);
          center.getChildren().addAll(line, someLabel);

          // define left
          VBox left = new VBox();
          left.setStyle("-fx-background-color: cornsilk;");
          GridPane grid = new GridPane();
          grid.setStyle("-fx-background-color: azure;");
          grid.add(new Text("Name:"), 0, 0);
          grid.add(new Label(
              "Karl Theodor Maria Nikolaus Johann Jacob Philipp Franz Joseph Sylvester Freiherr von und zu Guttenberg"
          ), 1, 0);

          // this bind should not be necessary but is required because
          // the layout seems to take up the preferred width of the grid's children rather
          // than inheriting the max width through the max width setting of the VBox.
      // grid.maxWidthProperty().bind(left.maxWidthProperty());

          stage.setScene(new Scene(pane, 800, 500));

      This is a BorderPane with a VBox as direct child which contains a GridPane. The GridPane contains a Label with a very long text.
      The VBox maxWidth is set so that all children of the VBox do not grow larger than that value. However, although the Label in the GridPane is truncated at the correct index to fit this value, container of the VBox is made as large as the Label. This is indicated by the large amount of white space between the nodes.
      When a value is set to the maxWidth property of the GridPane, the layout is calculated correctly.




            msladecek Martin Sládeček
            srheinnecjfx Sebastian Rheinnecker (Inactive)
            0 Vote for this issue
            0 Start watching this issue