How do I get all nodes in a parent in JavaFX?

后端 未结 6 1559
耶瑟儿~
耶瑟儿~ 2020-12-29 09:58

In C# I found a method that was pretty sweet that allowed you to get all the descendants and all of THEIR descendants from a specified control.

I\'m looking for a si

6条回答
  •  -上瘾入骨i
    2020-12-29 10:11

    public static ArrayList getAllNodes(Parent root) {
        ArrayList nodes = new ArrayList();
        addAllDescendents(root, nodes);
        return nodes;
    }
    
    private static void addAllDescendents(Parent parent, ArrayList nodes) {
        for (Node node : parent.getChildrenUnmodifiable()) {
            nodes.add(node);
            if (node instanceof Parent)
                addAllDescendents((Parent)node, nodes);
        }
    }
    

提交回复
热议问题