我正在尝试编写一个函数,它将从gridpane的所需索引返回一个按钮。我没有得到想要的结果。这是我的密码
public Node getNodeFromGridPane(GridPane gridPane)
{
int[] cord = new int[2];
cord=getCord(count);
int row=cord[0];
int col=cord[1];
System.out.println("Getting Label");
for (Node node : gridPane.getChildren())
{
if (GridPane.getColumnIndex(node) == col && GridPane.getRowIndex(node) == row)
{
System.out.println("AAA");
return node;
}
}
return null;
}
还有别的办法吗?
1条答案
按热度按时间wb1gzix01#
你提供的信息有限。为什么你没有得到想要的结果?
我用java编写了以下代码,用几个标签和一个按钮填充gridpane。
gridpane的外观:
程序输出为:
根据传递的列和行索引,此输出是正确的。