我想检索网格 Pane 中一个特定单元格的内容。我在单元格中放置了按钮
setConstraints(btt , 0 ,1 )
setConstraints(btt , 0 ,2 )
getChildren().add....
在我的情况下
GridPane.getChildren.get(10)
不好。我想直接转到单元格(4,2)并获取其内容。
最佳答案
好吧,我想如果没有解决方案可以通过列和行索引从网格 Pane 中获取特定节点,我有一个功能可以做到这一点,
private Node getNodeFromGridPane(GridPane gridPane, int col, int row) {
for (Node node : gridPane.getChildren()) {
if (GridPane.getColumnIndex(node) == col && GridPane.getRowIndex(node) == row) {
return node;
}
}
return null;
}
关于javafx GridPane 检索特定的单元格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20655024/