本文介绍了javafx GridPane 检索特定的单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检索网格窗格中一个特定单元格的内容.我已经将按钮放在带有
I want to retrieve the content of one specific cell in a Gridpane. I have put buttons in the cells with the
setConstraints(btt , 0 ,1 )
setConstraints(btt , 0 ,2 )
getChildren().add....
就我而言,GridPane.getChildren.get(10)
不好.我想直接进入单元格(4,2)并获取其内容.
In my case the GridPane.getChildren.get(10)
is not good. I want to go directly to the cell(4,2) and get its content.
推荐答案
好吧,我想如果没有解决方案可以通过列和行索引从 gridpane 获取特定节点,我有一个函数可以做到这一点,
Well I guess if there is no solution to get a specific node from gridpane by is column and row index, I have a function to do that,
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 检索特定的单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!