-1

I have to get an ImageView from a GridPane.

I use this code, but it is for Node, while I'm trying to change an Image in an ImageView (inside 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;
   }

Is there a solution?

I already searched to lots of posts, but there is not this problem solved. Thank you

James_D
  • 201,275
  • 16
  • 291
  • 322
Alberto32
  • 229
  • 1
  • 4
  • 14
  • 2
    You know that [an ImageView *is* a Node](http://docs.oracle.com/javase/8/javafx/api/javafx/scene/image/ImageView.html), right? Just check if the node is an instance of ImageView. – VGR Jul 26 '17 at 16:50

1 Answers1

1

On caller side you may do the next:

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

instanceof will care for both ImageView and null.

Dmytro Maslenko
  • 2,247
  • 9
  • 16