Get the number of rows in a JavaFX GridPane?

Viewed 13425

I initialized a GridPane through SceneBuilder and inside the controller I want to conditionally add a row to the GridPane. I do not want to store an int for how many rows I initialized, I want to be able to get the number of rows from the GridPane object. Is that possible?

4 Answers

In my case I used Java Reflections ( GridPane.java has private method getNumberOfRows() ):

Method method = gridPane.getClass().getDeclaredMethod("getNumberOfRows");
method.setAccessible(true);
Integer rows = (Integer) method.invoke(gridPane);

This works for me

GridPane.getRowConstraints().size()
Related