【问题标题】:How to Reference a Particular Node in a GridPane [duplicate]如何在 GridPane 中引用特定节点 [重复]
【发布时间】:2018-12-08 02:17:54
【问题描述】:

我有一个瓷砖网格,每个瓷砖顶部都有一个堆栈窗格,以便在每个瓷砖上放置一个形状。
我想有一种方法可以从网格上的特定图块中删除堆栈窗格,这意味着实际上它应该删除图块顶部的形状。
我可以将每个堆栈窗格存储在某种数组中并通过索引引用它吗?我使用嵌套的 for 循环填充网格。
我还获得了要删除的堆栈窗格的行和列。

【问题讨论】:

    标签: java javafx gridpane


    【解决方案1】:

    您可以存储对每个节点的引用,或者通过行-列索引动态检索节点:

    Node getChildByRowColumn(final GridPane gridPane, final int row, final int col){
    
        for(final Node node : gridPane.getChildren()){
            if (GridPane.getRowIndex(node) == null) continue ; //ignore Group 
            if(GridPane.getRowIndex(node) == row && GridPane.getColumnIndex(node) == col) return node;
        }
        return null;
    } 
    

    【讨论】:

    • 效果很好!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-23
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2015-09-17
    • 2014-06-24
    相关资源
    最近更新 更多