Get the number of rows in a JavaFX GridPane?
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);
Hej j will, try this method:
private int getRowCount(GridPane pane) {
int numRows = pane.getRowConstraints().size();
for (int i = 0; i < pane.getChildren().size(); i++) {
Node child = pane.getChildren().get(i);
if (child.isManaged()) {
Integer rowIndex = GridPane.getRowIndex(child);
if(rowIndex != null){
numRows = Math.max(numRows,rowIndex+1);
}
}
}
return numRows;
}
This worked for me.
Patrick