Only one responsive column in GridPane

492 Views Asked by At

I need to do something like the below in JavaFX:

Layout Example

Can you tell me how can I get only one column to change size (the middle one) in a GridPane layout? These black bordered rectangles are VBoxs. Basically, the width of VBoxs must stay the same and the width of this red marked area should resize. Any ideas or tips?

2

There are 2 best solutions below

5
On BEST ANSWER

Use column constraints to set the grow priorities to NEVER/ALWAYS. Assuming the GridPane contains 3 columns and no constraints have been added yet:

ColumnConstraints c1 = new ColumnConstraints();
c1.setHgrow(Priority.NEVER);

ColumnConstraints c2 = new ColumnConstraints();
c2.setHgrow(Priority.ALWAYS);

gridPane.getColumnConstraints().addAll(c1, c2, c1);
0
On

Eventhough this is doable, I think it is best to use BorderPane instead.