Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFx Finding source parent node with specific id?

Tags:

javafx

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(); 
like image 429
kingkong Avatar asked Aug 20 '13 16:08

kingkong


People also ask

What is getChildren in Javafx?

ObservableList<Node> getChildren() Gets the list of children of this Parent .

How many parents does an element of a Javafx scene have?

Every Scene needs exactly one Parent as the root .

Can a node be placed in a scene Javafx?

A node may occur at most once anywhere in the scene graph. Specifically, a node must appear no more than once in all of the following: as the root node of a Scene , the children ObservableList of a Parent , or as the clip of a Node . The scene graph must not have cycles.

What is the Parent class in Javafx?

Class Parent. The base class for all nodes that have children in the scene graph. This class handles all hierarchical scene graph operations, including adding/removing child nodes, marking branches dirty for layout and rendering, picking, bounds calculations, and executing the layout pass on each pulse.


1 Answers

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.

like image 89
Aaron Avatar answered Sep 30 '22 02:09

Aaron