【问题标题】:How to Get ImageView (not Node) from GridPane [duplicate]如何从 GridPane 获取 ImageView(不是节点)[重复]
【发布时间】:2017-07-26 15:45:42
【问题描述】:

我必须从 GridPane 获取 ImageView。

我使用此代码,但它适用于 Node,而我正在尝试更改 ImageView 中的图像(在 GridPane 内)。

private Node getNodeFromGridPane(GridPane gridPane, int col, int row) {
      for (Node node : gridPane.getChildren()) {
         if (GridPane.getColumnIndex(node) == col && GridPane.getRowIndex(node) == row) {
            System.out.println(node);
            return node;
         }
      }
      return null;
   }

有解决办法吗?

我已经搜索了很多帖子,但没有解决这个问题。 谢谢

【问题讨论】:

标签: javafx row gridpane


【解决方案1】:

在调用方你可以做下一个:

final Node foundNode = getNodeFromGridPane(gridPane, col, row);
if (foundNode instanceof ImageView) {
    //do something
}

instanceof 将同时处理 ImageView 和 null。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-17
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    相关资源
    最近更新 更多