1

I have in my javafx app an HBox with ImageViews, now I need some way to iterate through this HBox, but I can't find out an algorithm how to do it, I have tried to do something like this:

Object[] stack = stackWrapp.getChildren().toArray();

where stack is my HBox, but the ImageViews in this way will be duplicated, what I don't want. I don't know why So how can I do it..

Julik
  • 71
  • 3
  • 12

1 Answers1

1

You can do it like this:

for (Node child : stackWrapp.getChildren()) {
    ImageView imgView = (ImageView) child;
    ...
}

To be on the save side you can also do a type check before the casting, just in case there are other Nodes in your HBox than only ImageView.

hotzst
  • 7,238
  • 9
  • 41
  • 64