HGrow column constraints in GridPane work strangely if first cell has rowspan of more than 1.
For checking, please use the following application:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
public class GridPaneTest extends Application {
@Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
// 1
root.add(new Button("1 - I am for 2 cols"), 0, 0, 2, 1);
//
root.add(new Button("2"), 0, 1);
root.add(new Button("3"), 1, 1);
root.setGridLinesVisible(true);
root.setPrefWidth(500);
// 2
ColumnConstraints c1 = new ColumnConstraints();
c1.setHgrow(Priority.ALWAYS);
ColumnConstraints c2 = new ColumnConstraints();
c2.setHgrow(Priority.NEVER);
root.getColumnConstraints().addAll(c1, c2);
//
Scene scene = new Scene(root, 500, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
}
When commenting out sections "1" and "2", you can see how GridPane's layout is changing.
For checking, please use the following application:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
public class GridPaneTest extends Application {
@Override
public void start(Stage primaryStage) {
GridPane root = new GridPane();
// 1
root.add(new Button("1 - I am for 2 cols"), 0, 0, 2, 1);
//
root.add(new Button("2"), 0, 1);
root.add(new Button("3"), 1, 1);
root.setGridLinesVisible(true);
root.setPrefWidth(500);
// 2
ColumnConstraints c1 = new ColumnConstraints();
c1.setHgrow(Priority.ALWAYS);
ColumnConstraints c2 = new ColumnConstraints();
c2.setHgrow(Priority.NEVER);
root.getColumnConstraints().addAll(c1, c2);
//
Scene scene = new Scene(root, 500, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
}
When commenting out sections "1" and "2", you can see how GridPane's layout is changing.