This discussion is archived
2 Replies Latest reply: Feb 21, 2013 7:28 AM by svanimpe RSS

Weird behaviour when spanning colums in GridPane

svanimpe Newbie
Currently Being Moderated
Using column span seems to influence the size of all the columns spanned in a weird (as in: I can't figure it out) way.
With the code below, you would expect the second column to be the size of the button (the only node placed directly in it), and the first column to take up all remaining space.
But for some reason, the second column is bigger than the button. Note that in my original code (way more complex than the example below) the second column was over 300 pixels too wide.

The only workaround I found was to set the preferred size of the nodes in the first column, and to set a preferred column size as well (see commented lines). Nothing I tried on the second column seemed to have any effect.

Am I missing something here, or is this a bug ?
GridPane root = GridPaneBuilder.create()
        .padding(new Insets(10))
        .hgap(15)
        .vgap(15)
        .gridLinesVisible(true)
        .build();

root.getColumnConstraints().addAll(
        ColumnConstraintsBuilder.create()
            .hgrow(Priority.ALWAYS)
            //.prefWidth(200)
            .halignment(HPos.RIGHT)
            .build(),
        ColumnConstraintsBuilder.create()
            .hgrow(Priority.NEVER)
            .build());

TextField text = new TextField();
//text.setPrefWidth(200);
GridPane.setColumnSpan(text, 2);
root.add(text, 0, 0);

Button cancel = new Button("Cancel");
root.add(cancel, 0, 1);

Button save = new Button("Save");
root.add(save, 1, 1);

Scene scene = new Scene(root);

primaryStage.setTitle("GridPane Span Test");
primaryStage.setScene(scene);
primaryStage.show();

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points