Module javafx.graphics

# Package javafx.scene

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:

- `Scene` – Defines the scene to be rendered. It contains a `fill` variable that specifies the background of the scene, `width` and `height` variables that specify the size of the scene, and a `content` sequence that contains a list of "root" `Nodes` to be rendered onto the scene. This sequence of `Nodes` is the scene graph for this `Scene`. A `Scene` is rendered onto a `Stage`, which is the top-level container for JavaFX content.
- `Node` – Abstract base class for all nodes in the scene graph. Each node is either a "leaf" node with no child nodes or a "branch" node with zero or more child nodes. Each node in the tree has zero or one parent. Only a single node within each tree in the scene graph will have no parent, which is often referred to as the "root" node. There may be several trees in the scene graph. Some trees may be part of a `Scene`, in which case they are eligible to be displayed. Other trees might not be part of any `Scene`.

Branch nodes are of type `Parent` or subclasses thereof.

Leaf nodes are classes such as `Rectangle`, `Text`, `ImageView`, `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:

## 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, `Rectangle` provides `x`, `y`, `width`, `height` variables while `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:

- `boundsInLocal` – specifies the bounds of the `Node` in untransformed local coordinates.
- `boundsInParent` – specifies the bounds of the `Node` after all transformations have been applied. It is called "boundsInParent" because the rectangle will be relative to the parent's coordinate system.
- `layoutBounds` – specifies the rectangular bounds of the `Node` that should be used as the basis for layout calculations, and may differ from the visual bounds of the node. For shapes, Text, and ImageView, the default `layoutBounds` includes only the shape geometry.

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.

- Related Packages
  Module
  Package
  Description
  javafx.graphics
  javafx.scene.canvas
  Provides the set of classes for canvas, an immediate mode style of rendering API.
  javafx.controls
  javafx.scene.chart
  The JavaFX User Interface provides a set of chart components that are a very convenient way for data visualization.
  javafx.controls
  javafx.scene.control
  The JavaFX User Interface Controls (UI Controls or just Controls) are specialized Nodes in the JavaFX Scenegraph especially suited for reuse in many different application contexts.
  javafx.graphics
  javafx.scene.effect
  Provides the set of classes for attaching graphical filter effects to JavaFX Scene Graph Nodes.
  javafx.graphics
  javafx.scene.image
  Provides the set of classes for loading and displaying images.
  javafx.graphics
  javafx.scene.input
  Provides the set of classes for mouse and keyboard input event handling.
  javafx.graphics
  javafx.scene.layout
  Provides classes to support user interface layout.
  javafx.media
  javafx.scene.media
  Provides the set of classes for integrating audio and video into Java FX Applications.
  javafx.graphics
  javafx.scene.paint
  Provides the set of classes for colors and gradients used to fill shapes and backgrounds when rendering the scene graph.
  javafx.graphics
  javafx.scene.robot
  Provides API for simulating user interaction such as typing keys on the keyboard and using the mouse.
  javafx.graphics
  javafx.scene.shape
  Provides the set of 2D classes for defining and performing operations on objects related to two-dimensional geometry.
  javafx.graphics
  javafx.scene.text
  Provides the set of classes for fonts and renderable Text Node.
  javafx.graphics
  javafx.scene.transform
  Provides the set of convenient classes to perform rotating, scaling, shearing, and translation transformations for `Affine` objects.
  javafx.web
  javafx.scene.web
  This package provides means for loading and displaying Web content.
- Class
  Description
  AccessibleAction
  This enum describes the actions that an assistive technology such as a screen reader can request from the scene graph.
  AccessibleAttribute
  This enum describes the attributes that an assistive technology such as a screen reader can request from the scene graph.
  AccessibleAttribute.ToggleState
  This enum describes the values for `TOGGLE_STATE` attribute.
  AccessibleRole
  This enum describes the accessible role for a `Node`.
  AmbientLight
  A light that illuminates an object from all directions equally regardless of its position and orientation.
  CacheHint
  Cache hints for use with `Node.cacheHint`
  Camera
  Base class for a camera used to render a scene.
  Cursor
  A class to encapsulate the bitmap representation of the mouse cursor.
  DepthTest
  This enum defines the possible states for the depthTest flag in node.
  DirectionalLight
  A light that illuminates an object from a specific direction.
  Group
  A `Group` node contains an ObservableList of children that are rendered in order whenever this node is rendered.
  ImageCursor
  A custom image representation of the mouse cursor.
  LightBase
  The `LightBase` class is the base class for all objects that represent a form of light source.
  Node
  Base class for scene graph nodes.
  ParallelCamera
  Specifies a parallel camera for rendering a scene without perspective correction.
  Parent
  The base class for all nodes that have children in the scene graph.
  PerspectiveCamera
  Specifies a perspective camera for rendering a scene.
  PointLight
  A light source that radiates light equally in all directions away from itself.
  Scene
  The JavaFX `Scene` class is the container for all content in a scene graph.
  SceneAntialiasing
  The JavaFX `SceneAntialiasing` class specifies the level of anti-aliasing desired.
  SnapshotParameters
  Parameters used to specify the rendering attributes for Node snapshot.
  SnapshotResult
  This class holds the result of a snapshot operation.
  SpotLight
  A light source that radiates light in a cone in a specific direction away from itself.
  SubScene
  The `SubScene` class is the container for content in a scene graph.