Explain the JavaFX Application structure


In general, a JavaFX application will have three major components namely Stage, Scene and Nodes as shown in the following diagram.

Stage

A stage (a window) contains all the objects of a JavaFX application. It is represented by Stage class of the package javafx.stage. You have to call the show() method to display the contents of a stage.

Scene graph

A scene graph is a data structure similar to a tree, in modern graphical applications, it is a collection of nodes. In a JavaFX application the javafx.scene.The scene class holds all the contents of a scene graph.

  • While creating a scene it is mandatory to specify the root node.

  • In an instance, the scene object is added to only one stage.

Nodes

A node is a visual/graphical primitive object of a JavaFX application.

2D and 3D geometric objects (circle, sphere, etc.), UI control objects (button, checkbox, etc.), Container/layout objects (Border Pane, Grid Pane, etc.), media element objects (audio, video, image objects, etc.) are (some) examples of nodes in JavaFX.

Each node in the scene graph has a single parent, and the node which does not contain any parents is known as the root node. In the same way, every node has one or more children, and the node without children is termed as leaf node; a node with children is termed as a branch node.

The following are various kinds of root nodes in a JavaFX application.

  • Group − A group node is a collective node that contains a list of children nodes. Whenever the group node is rendered, all its child nodes are rendered in order. Any transformation, effect state applied to the group will be applied to all the child nodes.

  • Region − It is the base class of all the JavaFX Node-based UI Controls, such as Chart, Pane and Control.

  • WebView − This node manages the web engine and displays its contents.

  • Leaf Node − The node without child nodes is known as the leaf node. For example, Rectangle, Ellipse, Box, ImageView, MediaView are examples of leaf nodes.

Updated on: 13-Apr-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements