In C #, I found a method that was pretty nice, which allowed you to get all descendants and all their descendants from the specified control.
I am looking for a similar method for JavaFX.
I have seen that the Parent class is what I want to work with, as it is the class from which all Node classes bearing children are derived.
This is what I have so far (and I actually haven’t found anything on google with search queries such as “JavaFX get all nodes from the scene”):
public static ArrayList<Node> GetAllNodes(Parent root){ ArrayList<Node> Descendents = new ArrayList<>(); root.getChildrenUnmodifiable().stream().forEach(N -> { if (!Descendents.contains(N)) Descendents.add(N); if (N.getClass() == Parent.class) Descendents.addAll( GetAllNodes((Parent)N) ); }); }
So, how can I determine if N is a parent (or extended from a parent)? Am I doing it right? It seems that it does not work ... It captures all nodes from the root (parent) of Node, but not from nodes with children in them. I feel that this is what probably got the answer, but I'm just asking the question ... wrong. How can I do it?
java recursion javafx javafx-8
Will
source share