I have a grid of tiles with a stack pane on top of each tile in order to place a shape on each tile.
I want to have a method by which I can remove the stack pane from a particular tile on the grid, which means that in effect it should remove the shape on top of the tile.
Could I perhaps store each stack pane in an array of some sort and reference it by the index? I populate the grid by using a nested for loop.
I am also given the row and column of the stack pane that I want to remove.
Asked
Active
Viewed 547 times
0

c0der
- 18,467
- 6
- 33
- 65
1 Answers
2
You can store a reference to each node, or retrieve a node dynamically by row - column index:
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;
}

c0der
- 18,467
- 6
- 33
- 65
-
1It worked perfectly! Thanks a ton!! – Dec 08 '18 at 10:02