In fact, your gridpane is growing to fill all of its parent. Consider the code below, I added a background color (red) to the gridpane for debugging purposes.
Accordion accordion = new Accordion(); TitledPane titledPane = new TitledPane(); titledPane.setText("Title"); GridPane gridPane = new GridPane(); gridPane.setStyle("-fx-background-color:red"); gridPane.add(new TextArea("Hello"), 0, 0); gridPane.add(new TextArea("World"), 0, 1); titledPane.setContent(gridPane); accordion.getPanes().add(titledPane);
If you execute this code, gridpane will fill its entire parent (check that the red color covers the entire contents of titledpane).
However, the contents of the grid will not fill the entire column. If you try to resize the window, you will see that the text areas do not change in width with the grid. To fix this, you need to say that the first gridpane column will grow with the grid itself. The way to do this is to add the following restriction:
ColumnConstraints columnConstraints = new ColumnConstraints(); columnConstraints.setFillWidth(true); columnConstraints.setHgrow(Priority.ALWAYS); gridPane.getColumnConstraints().add(columnConstraints);
Rasha
source share