What is a "Node" in JavaFx/FXML?

Sargon1 picture Sargon1 · Nov 26, 2015 · Viewed 10.6k times · Source

What is meant by the word "Node" within context of JavaFx/FXML? If I search for this question, all I find are people using the term discussing something else, but no explanation. For example, this answer to the question: How do I open the JavaFX FileChooser from a controller class?:

For any node in your scene (for example, the root node; but any node you have injected with @FXML will do), do

chooser.showOpenDialog(node.getScene().getWindow());

What would the node be, and how for that matter would I "inject it with @FXML"?

Answer

Ojonugwa Jude Ochalifu picture Ojonugwa Jude Ochalifu · Aug 4, 2016

Before you understand what a Node is, it is also important to first of all understand what a Scene Graph is in JavaFX.

JavaFX applications consist of a Stage and a Scene or several scenes. The stage being the top-level container of your application. The Scene(s) on the other hand, contains all the content (User Interface elements) of your application (if your application has only one "page") or the content of one of the "pages" of your application, and exists in/on a stage. (To be clear here, by page I mean what the user interacts with, for instance, a login page.)

The Scene Graph is a graphical illustration of how all the stuff in your scene are laid out. This graph is represented in the form of a tree data structure.

A Node is an item in the scene graph.

I think this image explains this clearly.

enter image description here

Example of a Node is a Control, which is anything that can be manipulated by the user E.g., TextField, Button, TextArea

Photo Credit