Eli*_*ias 14 javafx cell gridpanel
我想检索Gridpane中一个特定单元格的内容.我把按钮放在了细胞中
setConstraints(btt , 0 ,1 )
setConstraints(btt , 0 ,2 )
getChildren().add....
Run Code Online (Sandbox Code Playgroud)
在我的情况下,这GridPane.getChildren.get(10)是不好的.我想直接进入单元格(4,2)并获取其内容.
Shr*_*ave 23
好吧,我想如果没有解决方案从gridpane获取特定节点的是列和行索引,我有一个函数来做到这一点,
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;
}
Run Code Online (Sandbox Code Playgroud)
假设您有一个8x8 girdPane,其中i是行并且j是列,您可以编写:
myGridPane.getChildren().get(i*8+j)
返回类型是一个对象,所以你必须抛出它,在我的例子中它是:
(StackPane) (myGridPane.getChildren().get(i*8+j))
| 归档时间: |
|
| 查看次数: |
19677 次 |
| 最近记录: |