I am writing a program using JavaFX in which I have
Borderpane -> Center -> VBox -> ScrollPane-> Gridpane
I would like to be able to add as many rows to the gridpane as I like and have the scrollpane automatically extend itself.
Note: I have some very long files so I only included the important bits. If you need the whole FXML or Controller file please leave me a comment.
Here is the FXML for my gridpane/scrollpane:
<BorderPane>
<center>
<VBox>
<children>
<ScrollPane fx:id="messageScrollPane" vbarPolicy="ALWAYS" hbarPolicy="NEVER" hmax="0.0" vmax="0.0">
<content>
<GridPane fx:id="messageBox" prefHeight="540.0" prefWidth="589.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
<RowConstraints maxHeight="Infinity" minHeight="10.0" prefHeight="30.0" vgrow="ALWAYS" />
</rowConstraints>
</GridPane>
</content>
</ScrollPane>
</children>
</VBox>
</center>
</BorderPane>
I have the following code inside of my Controller for the FXML
@FXML
private GridPane messageBox;
if (me.getMail().size() > 0) {
for (int i = 0; i < me.getMail().size(); i++) {
messageBox.add(new Label(me.getMail().get(i).toString()), 0, rowNum);
rowNum++;
}
}
Thank you all for your help!
Ryan
ScrollPane
in the Documentation, try to use it, (hoping it will help you), here – Bo Halim