JavaFx Finding source parent node with specific id?

javafx

Solution

You can lookup any Node by its ID from the Scene object.

For example:

Scene scene = source.getScene();
Node nodeToFind = scene.lookup("#nodeToFindId");

The ID is a CSS selector (id), or an FX ID. It has to be set up on the node without the '#' character. When invoking the method 'lookup', the '#' character has to precede the ID, like above.

Problem

Is there is the way to find parent Node ( high in hierarchy ) via method? Element id or class can be use. Any alternative to something like this? ``` source.getParent().getParent().getParent().getParent().getParent().getParent(); ```

Original source