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

后端 未结 6 1562
耶瑟儿~
耶瑟儿~ 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:08

    Unfortunately this won't get subnodes for most container components. If you try a TabPane as parent, you'll find no children, but you can find tabs in it with getTabs(). The same is with SplitPane and other. So every container will require a specific approach.

    You could use node.lookupAll("*"), but it also doesn't look inside.

    The solution could be a "Prototype" pattern - creating a meta class with common interface of getChildren() method, which is realized in subclasses - one for each type.

    Approach example is given here.

提交回复
热议问题