APIdia Launch Partner
Top Description Classes Enums
module javafx.graphics

Package javafx.scene


Provides the core set of base classes for the JavaFX Scene Graph API. A scene graph is a tree-like data structure, where each item in the tree has zero or one parent and zero or more children.

The two primary classes in this package are:

Branch nodes are of type Parent or subclasses thereof.

Leaf nodes are classes such as javafx.scene.shape.Rectangle, javafx.scene.text.Text, javafx.scene.image.ImageView, javafx.scene.media.MediaView, or other such leaf classes which cannot have children.

A node may occur at most once anywhere in the scene graph. Specifically, a node must appear no more than once in the children list of a Parent or as the clip of a Node. See the Node class for more details on these restrictions.

Example

An example JavaFX scene graph is as follows:

package example;

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.text.Text;
import javafx.scene.text.Font;

public class Example extends Application {

    @Override public void start(Stage stage) {

        Group root = new Group();
        Scene scene = new Scene(root, 200, 150);
        scene.setFill(Color.LIGHTGRAY);

        Circle circle = new Circle(60, 40, 30, Color.GREEN);

        Text text = new Text(10, 90, "JavaFX Scene");
        text.setFill(Color.DARKRED);

        Font font = new Font(20);
        text.setFont(font);

        root.getChildren().add(circle);
        root.getChildren().add(text);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}

The above example will generate the following image:

A visual rendering of the JavaFX Scene example

Coordinate System and Transformations

The Node class defines a traditional computer graphics "local" coordinate system in which the x axis increases to the right and the y axis increases downwards. The concrete node classes for shapes provide variables for defining the geometry and location of the shape within this local coordinate space. For example, javafx.scene.shape.Rectangle provides x, y, width, height variables while javafx.scene.shape.Circle provides centerX, centerY, and radius.

Any Node can have transformations applied to it. These include translation, rotation, scaling, or shearing transformations. A transformation will change the position, orientation, or size of the coordinate system as viewed from the parent of the node that has been transformed.

See the Node class for more information on transformations.

Bounding Rectangle

Since every Node has transformations, every Node's geometric bounding rectangle can be described differently depending on whether transformations are accounted for or not.

Each Node has the following properties which specifies these bounding rectangles:

See the Node class for more information on bounding rectangles.

CSS

The JavaFX Scene Graph provides the facility to style nodes using CSS (Cascading Style Sheets). The Node class contains id, styleClass, and style variables are used by CSS selectors to find nodes to which styles should be applied. The Scene class contains the stylesheets variable which is a sequence of URLs that reference CSS style sheets that are to be applied to the nodes within that scene.

For further information about CSS, how to apply CSS styles to nodes, and what properties are available for styling, see the CSS Reference Guide.

Class Summary

Modifier and TypeClass and Description
public class
AmbientLight

A light that illuminates an object from all directions equally regardless of its position and orientation.

public abstract class
Camera

Base class for a camera used to render a scene.

pack-priv class
CssStyleHelper

The StyleHelper is a helper class used for applying CSS information to Nodes.

public abstract class
Cursor

A class to encapsulate the bitmap representation of the mouse cursor.

public class
DirectionalLight

A light that illuminates an object from a specific direction.

public class
Group

A Group node contains an ObservableList of children that are rendered in order whenever this node is rendered.

public class
ImageCursor

A custom image representation of the mouse cursor.

public abstract class
LightBase

The LightBase class is the base class for all objects that represent a form of light source.

public abstract class
Node

Base class for scene graph nodes.

public class
ParallelCamera

Specifies a parallel camera for rendering a scene without perspective correction.

public abstract class
Parent

The base class for all nodes that have children in the scene graph.

public class
PerspectiveCamera

Specifies a perspective camera for rendering a scene.

public class
PointLight

A light source that radiates light equally in all directions away from itself.

public class
Scene

The JavaFX Scene class is the container for all content in a scene graph.

public class
SceneAntialiasing

The JavaFX SceneAntialiasing class specifies the level of anti-aliasing desired.

public class
SnapshotParameters

Parameters used to specify the rendering attributes for Node snapshot.

public class
SnapshotResult

This class holds the result of a snapshot operation.

public class
SpotLight

A light source that radiates light in a cone in a specific direction away from itself.

public class
SubScene

The SubScene class is the container for content in a scene graph.

Enum Summary

Modifier and TypeEnum and Description
public enum
AccessibleAction

This enum describes the actions that an assistive technology such as a screen reader can request from the scene graph.

public enum
AccessibleAttribute

This enum describes the attributes that an assistive technology such as a screen reader can request from the scene graph.

public enum
AccessibleRole

This enum describes the accessible role for a Node.

public enum
CacheHint

Cache hints for use with Node.cacheHint

public enum
DepthTest

This enum defines the possible states for the depthTest flag in node.

public enum
TraversalDirection

Specifies the direction of focus traversal.