Institute of Computer Science
  1. Courses
  2. 2019/20 spring
  3. Object-Oriented Programming (Narva College) (LTAT.NR.003)
ET
Log in

Object-Oriented Programming (Narva College) 2019/20 spring

  • Home
  • Materials
  • Grading
  • Java Glossary
  • Cheat sheet (S1-S6)
  • Source Example
  • Links
Chapter 7

Scene graph

A JavaFX scene graph is a starting point in constructing a JavaFX application. The scene graph is a hierarchical tree of nodes that represents all of the visual elements of the application's user interface. A single element in the scene graph is called a node. Each node is classified as either a branch node (meaning that it can have children), or a leaf node (meaning that it cannot have children). The first node in the tree is always called the root node, and it never has a parent. Study the general inheritance diagram:

The JavaFX API defines a number of classes that can act as the root, a branch or a leaf node. However, three of them are the most significant:

  • Node: the abstract base class for all scene graph nodes.
  • Parent: the abstract base class for all branch nodes. (This class directly extends Node class).
  • Scene: the base container class for all content in the scene graph.

These base classes define important functionality that is subsequently inherited by subclasses (including the paint order, visibility, composition of transformations, support for CSS styling, and so on). Some branch node classes that inherit directly from the Parent class are Group, Region, and WebView. The leaf node classes are defined throughout a number of additional packages, such as javafx.scene.shape and javafx.scene.text.

Let's try to compose the scene graph for our BlackSquare application.

The scene graph is very laconic in this case. The Group type object acts as the root node. The Rectangle type object is a leaf node because it does not (and cannot) have any children. The scene graph cannot be even more reduced because the class Rectangle itself cannot be the root node (this class is not a subclass of Parent class).

Used resources:

JavaFX tutorial "Working with the JavaFX Scene Graph".

Chapter 7
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment