JavaFx Finding source parent node with specific id?


Question

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(); 
1
7
8/20/2013 4:32:13 PM

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.

11
11/4/2014 11:52:33 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon