【发布时间】:2016-07-29 06:40:44
【问题描述】:
我有一个网格窗格,行数可能是不确定的。 如何添加网格窗格的数字行? 或者如何在gridpane的最后添加?
谢谢。
【问题讨论】:
-
我真的不清楚你想问什么。要获取
GridPane的行数吗?或者您想将元素添加到指定的行中?还是?
标签: javafx
我有一个网格窗格,行数可能是不确定的。 如何添加网格窗格的数字行? 或者如何在gridpane的最后添加?
谢谢。
【问题讨论】:
GridPane 的行数吗?或者您想将元素添加到指定的行中?还是?
标签: javafx
只需找到从@ 987654321的孩子最大行指数@:
GridPane gridPane = ...
int maxIndex = gridPane.getChildren().stream().mapToInt(n -> {
Integer row = GridPane.getRowIndex(n);
Integer rowSpan = GridPane.getRowSpan(n);
// default values are 0 / 1 respecively
return (row == null ? 0 : row) + (rowSpan == null ? 0 : rowSpan - 1);
}).max().orElse(-1);
// add nodes after last row
gridPane.addRow(maxIndex+1, node1, node2, ...);
【讨论】: