【问题标题】:get the number row of gridpane Javafx获取gridpane Javafx的行数
【发布时间】:2016-07-29 06:40:44
【问题描述】:

我有一个网格窗格,行数可能是不确定的。 如何添加网格窗格的数字行? 或者如何在gridpane的最后添加?

谢谢。

【问题讨论】:

  • 我真的不清楚你想问什么。要获取GridPane 的行数吗?或者您想将元素添加到指定的行中?还是?

标签: javafx


【解决方案1】:

只需找到从@ 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, ...);

【讨论】:

    猜你喜欢
    • 2014-01-13
    • 2014-05-09
    • 2013-01-23
    • 2015-09-17
    • 1970-01-01
    • 2021-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多