JavaFX looping over scenegraph controls
java, javafx, javafx-2
Solution
You need to scan recursively. For example:
private void scanInputControls(Pane parent) {
for (Node component : parent.getChildren()) {
if (component instanceof Pane) {
//if the component is a container, scan its children
scanInputControls((Pane) component);
} else if (component instanceof IInputControl) {
//if the component is an instance of IInputControl, add to list
lstInputControl.add((IInputControl) component);
}
}
}
Problem
How can I loop over the controls of the scene ? I tried with getChildrenUnmodifiable() but it returns only the first level of children. ``` public void rec(Node node){ f(node); if (node instanceof Parent) { Iterator<Node> i = ((Parent) node).getChildrenUnmodifiable().iterator(); while (i.hasNext()){ this.rec(i.next()); } } } ```