package test; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.stage.Stage; public class GridPaneColSpan extends Application { private boolean showBug = true; @Override public void start(Stage primaryStage) { GridPane p = new GridPane(); { { Label l = new Label("C1"); GridPane.setColumnIndex(l, 0); GridPane.setRowIndex(l, 0); p.getChildren().add(l); } { TextField f = new TextField(); GridPane.setColumnIndex(f, 1); GridPane.setRowIndex(f, 0); GridPane.setColumnSpan(f, 2); GridPane.setHgrow(f, Priority.ALWAYS); p.getChildren().add(f); } } if( ! showBug ) { { Label l = new Label("C2-Alternate"); GridPane.setColumnIndex(l, 0); GridPane.setRowIndex(l, 1); p.getChildren().add(l); } { TextField f = new TextField(); GridPane.setColumnIndex(f, 1); GridPane.setRowIndex(f, 1); GridPane.setColumnSpan(f, 2); GridPane.setHgrow(f, Priority.ALWAYS); p.getChildren().add(f); } } else { { Label l = new Label("C2"); GridPane.setColumnIndex(l, 0); GridPane.setRowIndex(l, 1); p.getChildren().add(l); } { GridPane sub = new GridPane(); { TextField f = new TextField(); GridPane.setColumnIndex(f, 0); GridPane.setRowIndex(f, 0); GridPane.setHgrow(f, Priority.ALWAYS); sub.getChildren().add(f); } { TextField f = new TextField(); GridPane.setColumnIndex(f, 1); GridPane.setRowIndex(f, 0); GridPane.setHgrow(f, Priority.ALWAYS); sub.getChildren().add(f); } { TextField f = new TextField(); GridPane.setColumnIndex(f, 2); GridPane.setRowIndex(f, 0); GridPane.setHgrow(f, Priority.ALWAYS); sub.getChildren().add(f); } { TextField f = new TextField(); GridPane.setColumnIndex(f, 4); GridPane.setRowIndex(f, 0); GridPane.setHgrow(f, Priority.ALWAYS); sub.getChildren().add(f); } GridPane.setHgrow(sub, Priority.ALWAYS); GridPane.setRowIndex(sub, 1); GridPane.setColumnIndex(sub, 1); GridPane.setColumnSpan(sub, 2); p.getChildren().add(sub); } } { { Label l = new Label("C3"); GridPane.setColumnIndex(l, 0); GridPane.setRowIndex(l, 2); p.getChildren().add(l); } { TextField f = new TextField(); GridPane.setColumnIndex(f, 1); GridPane.setRowIndex(f, 2); GridPane.setHgrow(f, Priority.ALWAYS); p.getChildren().add(f); } { Button b = new Button(); GridPane.setColumnIndex(b, 2); GridPane.setRowIndex(b, 2); p.getChildren().add(b); } } Scene s = new Scene(p); primaryStage.setScene(s); primaryStage.setWidth(300); primaryStage.setHeight(300); primaryStage.show(); } public static void main(String[] args) { launch(args); } }