Overview
Base class for scene graph nodes. A scene graph is a set of tree data structures where every item has zero or one parent, and each item is either a "leaf" with zero sub-items or a "branch" with zero or more sub-items.
Each item in the scene graph is called a Node
. Branch nodes are
either of type Group or of type CustomNode, 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 nodes. Only a single node within each scene graph tree 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 part of any Scene.
A node may occur at most once anywhere in the scene graph. Specifically,
a node must appear no more than once in all of the following:
in the content sequence of a
Group, in the content sequence of a Scene,
as the clip of a Node, or as the return value
of the create
function of a CustomNode subclass.
The scene graph must not have cycles. A cycle would exist if a node is a parent of itself in the tree, considering the Group content sequence, Node clip, and CustomNode relationships mentioned above.
If code attempts to modify the scene graph in any way that violates the above rules, the modification attempt is ignored and the scene graph is restored to its previous state.
It is possible to rearrange the structure of the scene graph, for
example, to move a subtree from one location in the scene graph to
another. In order to do this, one must first remove the subtree from
its old location before inserting it at the new location. Note that
there is no way to change the "child" of a CustomNode. Once
a node has been returned from the CustomNode create
function, that node cannot be reused elsewhere in the scene graph.
String ID
Each node in the scene graph can be given a unique id. This id is much like the "id" attribute of an HTML tag in that it is up to the designer and developer to ensure that theid
is unique within the scene graph.
A convenience function called lookup(String) can be used to find
a node with a unique id within the scene graph, or within a subtree of the
scene graph.
Coordinate System
TheNode
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 configuring 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
.
Transformations
AnyNode
can have transformations applied to it. These include
translation, rotation, scaling, or shearing transformations.
A translation transformation is one which shifts the origin of the
node's coordinate space along either the x or y axis. For example, if you
create a javafx.scene.shape.Rectangle which is drawn at the origin
(x=0, y=0) and has a width of 100 and a height of 50, and then apply a
javafx.scene.transform.Translate with a shift of 10 along the x axis
(x=10), then the rectangle will appear drawn at (x=10, y=0) and remain
100 points wide and 50 tall. Note that the origin was shifted, not the
x
variable of the rectangle.
A rotation transformation is one which rotates the coordinate space of the node about a specified "pivot" point, causing the node to appear rotated. For example, if you create a javafx.scene.shape.Rectangle which is drawn at the origin (x=0, y=0) and has a width of 100 and height of 30 and you apply a javafx.scene.transform.Rotate with a 90 degree rotation (angle=90) and a pivot at the origin (pivotX=0, pivotY=0), then the rectangle will be drawn as if its x and y were zero but its height was 100 and its width -30. That is, it is as if a pin is being stuck at the top left corner and the rectangle is rotating 90 degrees clockwise around that pin. If the pivot point is instead placed in the center of the rectangle (at point x=50, y=15) then the rectangle will instead appear to rotate about its center.
Note that as with all transformations, the x, y, width, and height variables of the rectangle (which remain relative to the local coordinate space) have not changed, but rather the transformation alters the entire coordinate space of the rectangle.
A scaling transformation causes a node to either appear larger or
smaller depending on the scaling factor. Scaling alters the coordinate space
of the node such that each unit of distance along the axis in local
coordinates is multipled by the scale factor. As with rotation
transformations, scaling transformations are applied about a "pivot" point.
You can think of this as the point in the Node around which you "zoom". For
example, if you create a javafx.scene.shape.Rectangle with a
strokeWidth
of 5, and a width and height of 50, and you apply a
javafx.scene.transform.Scale with scale factors (x=2.0, y=2.0) and
a pivot at the origin (pivotX=0, pivotY=0), the entire rectangle
(including the stroke) will double in size, growing to the right and
downwards from the origin.
A shearing transformation, sometimes called a skew, effectively rotates one axis so that the x and y axes are no longer perpendicular.
Multiple transformations may be applied to a node by specifying an ordered chain of transforms. The order in which the transforms are applied is defined by the sequence specified in the transforms variable.
Bounding Rectangles
Since everyNode
has transformations, every Node
's geometric
bounding rectangle that can be described differently depending on whether
transformations are accounted for or not.
At the simplest, Node
's have a read-only boundsInLocal
variable which specifies the bounding rectangle of the Node
in
untransformed local coordinates. boundsInLocal
includes the
Node
's shape geometry, including any space required for a
non-zero stroke that may fall outside the local position/size variables,
its clip and effect variables (if set).
The layoutBounds variable defines the rectangular bounds of a
Node
that should be used as the basis for layout calculations. By
default this will be equal to boundsInLocal
plus transforms set
in the transforms
variable but does NOT include transforms set by
the explicit translateX, translateY, scaleX,
scaleY, and rotate variables.
Finally, each Node
also has a read-only boundsInParent
variable which specifies the bounding rectangle of the Node
after all
transformations have been applied, including those set in transforms,
translateX, translateY, scaleX, scaleY,
and rotate. It is called "boundsInParent" because the rectangle
will be defined in terms of the parent Node
's coordinate system.
Profile: common
Variable Summary
access | name | type | Can Read | Can Init | Can Write | Default Value | description |
---|---|---|---|---|---|---|---|
public | blocksMouse | Boolean | false |
If If Profile: common conditional mouse |
|||
public-read | boundsInLocal | Bounds |
The rectangular bounds of this The rectangular bounds of this
Note that this method does not take the node's visibility into account;
the test is based on the geometry of this This variable will always be a non-null value. Note that boundsInLocal is automatically recomputed whenever the geometry of a node changes. For this reason, it is an error to bind any of these values in a node to an expression that depends upon this variable. For example, the "x" or "y" variables of a shape should never be bound to boundsInLocal for the purpose of positioning the node. Profile: common |
||||
public-read | boundsInParent | Bounds |
The rectangular bounds of this The rectangular bounds of this
The resulting bounds will be conceptually in the coordinate space of the
Note that this method does not take the node's visibility into account;
the test is based on the geometry of this This variable will always be a non-null value. Note that boundsInParent is automatically recomputed whenever the geometry of a node changes, or when any of the following change: the transforms sequence, the translateX, translateY, layoutX, layoutY, scaleX, scaleY, or rotate variable. For this reason, it is an error to bind any of these values in a node to an expression that depends upon this variable. For example, the "x" or "y" variables of a shape, or translateX, translateY should never be bound to boundsInParent for the purpose of positioning the node. Profile: common |
||||
public | cache | Boolean | false |
A performance hint to the system to indicate that this A performance hint to the system to indicate that this Profile: common |
|||
public | clip | Node | null |
Specifies a Specifies a For example, you can use an javafx.scene.image.ImageView Node as a mask to represent the Clip. Or you could use one of the geometric shape Nodes such as javafx.scene.shape.Rectangle or javafx.scene.shape.Circle. Or you could use a javafx.scene.text.Text node to represent the Clip. See the class documentation for Node for scene graph structure restrictions on setting the clip. If these restrictions are violated by a change to the clip variable, the change is ignored and the previous value of the clip variable is restored. nullProfile: common conditional clip |
|||
public | cursor | Cursor | null |
Defines the mouse cursor for this Defines the mouse cursor for this Profile: common conditional cursor |
|||
public | disable | Boolean | false |
Sets the individual disabled state of this Sets the individual disabled state of this Profile: common |
|||
public-read | disabled | Boolean | false |
Indicates whether or not this Indicates whether or not this
A disabled
A disabled Profile: common |
|||
public | effect | Effect | null |
Specifies an effect to apply to this |
|||
public-read protected | focused | Boolean | subclass | subclass | false |
Indicates whether this Indicates whether this Profile: common |
|
public | focusTraversable | Boolean | fase |
Specifies whether this Specifies whether this Profile: common |
|||
public-read protected | hover | Boolean | subclass | subclass | false |
Whether or not this Whether or not this NOTE: the current implementation of hover relies on mouse enter and exit events to determine whether this Node is in the hover state; this means that this feature is currently supported only on systems that have a mouse. Future implementations may provide alternative means of supporting hover. falseProfile: common |
|
public | id | String | empty string |
The id of this The id of this Profile: common |
|||
public-read protected | layoutBounds | Bounds | subclass | subclass |
The rectangular bounds that should be used in calculations for both manual
and automatic layout of this The rectangular bounds that should be used in calculations for both manual
and automatic layout of this
Note that the layoutX, layoutY, translateX, and
translateY variables are not included in the layoutBounds.
This is important because layout code must first determine the current
size and location of the layoutBounds is automatically recomputed whenever the geometry of a node changes. For this reason, it is an error to bind any of these values in a node to an expression that depends upon this variable. For example, the "x" or "y" variables of a shape should never be bound to layoutBounds for the purpose of positioning the node. Profile: common |
||
public | layoutInfo | LayoutInfoBase |
Hook for node-specific layout information used by layout containers. Hook for node-specific layout information used by layout containers. If the node is not a child of a container which supports layout info, this variable will be ignored. Note that layoutInfo object literals may be shared across nodes, which means altering the vars in layoutInfo will affect all such nodes. |
||||
public | layoutX | Number | 0 |
Defines the X coordinate of the translation that is added to the
transformed coordinates of this Defines the X coordinate of the translation that is added to the
transformed coordinates of this For example, if Profile: common |
|||
public | layoutY | Number | 0 |
Defines the Y coordinate of the translation that is added to the
transformed coordinates of this Defines the Y coordinate of the translation that is added to the
transformed coordinates of this For example, if Profile: common |
|||
public | onKeyPressed | function(:KeyEvent):Void |
Defines a function to be called when this |
||||
public | onKeyReleased | function(:KeyEvent):Void |
Defines a function to be called when this |
||||
public | onKeyTyped | function(:KeyEvent):Void |
Defines a function to be called when this Defines a function to be called when this Profile: common conditional keyboard |
||||
public | onMouseClicked | function(:MouseEvent):Void |
Defines a function to be called when a mouse button has been clicked
(pressed and released) on this |
||||
public | onMouseDragged | function(:MouseEvent):Void |
Defines a function to be called when a mouse button is pressed
on this |
||||
public | onMouseEntered | function(:MouseEvent):Void |
Defines a function to be called when the mouse enters this |
||||
public | onMouseExited | function(:MouseEvent):Void |
Defines a function to be called when the mouse exits this |
||||
public | onMouseMoved | function(:MouseEvent):Void |
Defines a function to be called when mouse cursor moves within
this |
||||
public | onMousePressed | function(:MouseEvent):Void |
Defines a function to be called when a mouse button
has been pressed on this |
||||
public | onMouseReleased | function(:MouseEvent):Void |
Defines a function to be called when a mouse button
has been released on this |
||||
public | onMouseWheelMoved | function(:MouseEvent):Void |
Defines a function to be called when the mouse scroll wheel has moved. |
||||
public | opacity | Number | 1.0 |
Specifies how opaque (that is, solid) the Specifies how opaque (that is, solid) the A visible node with any opacity setting still receives mouse events and can receive keyboard focus. For example, if you want to have a large invisible rectangle overlay all Nodes in the scene graph in order to intercept mouse events but not be visible to the user, you could create a large Rectangle that had an opacity of 0%. Opacity is specified as a value between 0 and 1. Values less than 0 or greater than 1 are clipped to 0 and 1 respectively. On some platforms ImageView might not support opacity variable. 1.0Profile: common |
|||
public-read package | parent | Parent | null |
The parent of this The parent of this Profile: common |
|||
public-read protected | pressed | Boolean | subclass | subclass | false |
Whether or not the Whether or not the Profile: common |
|
public | rotate | Number | 0.0 |
Defines the angle of rotation about the Defines the angle of rotation about the This rotation factor is not included in layoutBounds by default, which makes it ideal for rotating the entire node after all effects and transforms have been taken into account. The pivot point about which the rotation occurs is the center of the untransformed layoutBounds.
Note that because the pivot point is computed as the center of this
Profile: common |
|||
public | scaleX | Number | 1.0 |
Defines the factor by which coordinates are scaled about the center of the
object along the X axis of this Defines the factor by which coordinates are scaled about the center of the
object along the X axis of this This scale factor is not included in layoutBounds by default, which makes it ideal for scaling the entire node after all effects and transforms have been taken into account. The pivot point about which the scale occurs is the center of the untransformed layoutBounds. 1.0Profile: common |
|||
public | scaleY | Number | 1.0 |
Defines the factor by which coordinates are scaled about the center of the
object along the Y axis of this Defines the factor by which coordinates are scaled about the center of the
object along the Y axis of this This scale factor is not included in layoutBounds by default, which makes it ideal for scaling the entire node after all effects and transforms have been taken into account. The pivot point about which the scale occurs is the center of the untransformed layoutBounds. 1.0Profile: common |
|||
public-read package | scene | Scene | null |
The Scene that this The Scene that this Profile: common |
|||
public | style | String | empty string |
A string representation of the CSS style associated with this specific Node. A string representation of the CSS style associated with this specific Node. This is exactly analogous to the "style" attribute on an HTML element, but uses the syntax defined in JavaFX CSS. empty stringProfile: desktop |
|||
public | styleClass | String | empty string |
A String identifier which can be used to logically group Nodes, specifically for an external style engine. A String identifier which can be used to logically group Nodes, specifically for an external style engine. This variable is exactly analogous to the styleClass attribute on an HTML element. empty stringProfile: common |
|||
public | transforms | Transform[] | empty |
Defines the sequence of javafx.scene.transform.Transform objects
to be applied to this Defines the sequence of javafx.scene.transform.Transform objects
to be applied to this By default, layoutBounds is defined as the local bounds with all the transforms in this sequence applied. emptyProfile: common |
|||
public | translateX | Number | 0 |
Defines the X coordinate of the translation that is added to the
transformed coordinates of this Defines the X coordinate of the translation that is added to the
transformed coordinates of this This variable can be used to alter the location of a Node without disturbing its layout bounds, which makes it useful for animating a node's location. 0Profile: common |
|||
public | translateY | Number | 0 |
Defines the Y coordinate of the translation that is added to the
transformed coordinates of this Defines the Y coordinate of the translation that is added to the
transformed coordinates of this This variable can be used to alter the location of a Node without disturbing its layout bounds, which makes it useful for animating a node's location. 0Profile: common |
|||
public | visible | Boolean | true |
Specifies whether this Specifies whether this Profile: common |
Inherited Variables
Function Summary
- public contains(localX: Number, localY: Number) : Boolean
-
Returns
true
if the given point (specified in the local coordinate space of thisNode
) is contained within the shape of thisNode
.Returns
true
if the given point (specified in the local coordinate space of thisNode
) is contained within the shape of thisNode
. Note that this method does not take visibility into account; the test is based on the geometry of thisNode
only.-
Parameters
- localX
- localY
-
Returns
- Boolean
Profile: common
- public contains(localPoint: Point2D) : Boolean
-
Returns
true
if the given point (specified in the local coordinate space of thisNode
) is contained within the shape of thisNode
.Returns
true
if the given point (specified in the local coordinate space of thisNode
) is contained within the shape of thisNode
. Note that this method does not take visibility into account; the test is based on the geometry of thisNode
only.-
Parameters
- localPoint
-
Returns
- Boolean
Profile: common
- protected impl_boundsChanged() : Void
-
Invoked by anything which may cause the boundsInLocal to change.
Invoked by anything which may cause the boundsInLocal to change. We do it this way to avoid actually having to recompute the bounds (ie, if I put an on replace trigger on boundsInLocal, then it would force the recomputation of bounds in every case even in situations where we don't need to be computing bounds. This way we don't do that).
Invoking this function will cause the entire chain of parent nodes to this node to be notified that their child bounds have changed, which may cause them to revalidate their bounds if somebody is listening to their bounds, or in the simplest case will just walk up the tree and notify that bounds have changed.
- protected abstract impl_createPGNode() : com.sun.javafx.sg.PGNode
- public impl_effectChanged() : Void
- public impl_getLeafTransform() : com.sun.javafx.geom.AffineTransform
- public impl_getPGNode() : com.sun.javafx.sg.PGNode
- public impl_getPivotX() : Number
- public impl_getPivotY() : Number
- public impl_isInitialized() : Boolean
-
Note I use a private variable / public function pair to avoid creation of a Location object and to prevent binding to the initialized variable.
Note I use a private variable / public function pair to avoid creation of a Location object and to prevent binding to the initialized variable.
-
Returns
- Boolean
- protected impl_processKeyEvent(e: KeyEvent) : Void
- protected impl_processMouseEvent(e: MouseEvent) : Void
- public impl_requestFocusImpl(f: com.sun.javafx.functions.Function0) : Void
- public impl_transformsChanged() : Void
- public intersects(localX: Number, localY: Number, localWidth: Number, localHeight: Number) : Boolean
-
Returns
true
if the given rectangle (specified in the local coordinate space of thisNode
) intersects the shape of thisNode
.Returns
true
if the given rectangle (specified in the local coordinate space of thisNode
) intersects the shape of thisNode
. Note that this method does not take visibility into account; the test is based on the geometry of thisNode
only. The default behavior of this function is simply to check if the given coordinates intersect with the local bounds.-
Parameters
- localX
- localY
- localWidth
- localHeight
-
Returns
- Boolean
Profile: common
- public intersects(localBounds: Bounds) : Boolean
-
Returns
true
if the given bounds (specified in the local coordinate space of thisNode
) intersects the shape of thisNode
.Returns
true
if the given bounds (specified in the local coordinate space of thisNode
) intersects the shape of thisNode
. Note that this method does not take visibility into account; the test is based on the geometry of thisNode
only. The default behavior of this function is simply to check if the given coordinates intersect with the local bounds.-
Parameters
- localBounds
-
Returns
- Boolean
Profile: common
- public localToParent(localX: Number, localY: Number) : Point2D
- public localToParent(localPoint: Point2D) : Point2D
- public localToParent(localBounds: Bounds) : Bounds
- public localToScene(localX: Number, localY: Number) : Point2D
-
Transforms a point from the local coordinate space of this
Node
into the coordinate space of its javafx.scene.Scene.Transforms a point from the local coordinate space of this
Node
into the coordinate space of its javafx.scene.Scene.-
Parameters
- localX
- localY
-
Returns
- Point2D
Profile: common
- public localToScene(localPoint: Point2D) : Point2D
-
Transforms a point from the local coordinate space of this
Node
into the coordinate space of its javafx.scene.Scene.Transforms a point from the local coordinate space of this
Node
into the coordinate space of its javafx.scene.Scene.-
Parameters
- localPoint
-
Returns
- Point2D
Profile: common
- public localToScene(localBounds: Bounds) : Bounds
-
Transforms a bounds from the local coordinate space of this
Node
into the coordinate space of its javafx.scene.Scene.Transforms a bounds from the local coordinate space of this
Node
into the coordinate space of its javafx.scene.Scene.-
Parameters
- localBounds
-
Returns
- Bounds
Profile: common
- public lookup(id: java.lang.String) : Node
-
Finds this
Node
, or the first subnode, with the given id.Finds this
Node
, or the first subnode, with the given id. If multiple subnodes have the same id, this function returns one of them. Which node it returns in that case is unspecified.-
Parameters
- id
- The id of the node to find
-
Returns
- Node
-
The first node, starting from this
Node
, which has an id ofid
.
Profile: common
- public parentToLocal(parentX: Number, parentY: Number) : Point2D
- public parentToLocal(parentPoint: Point2D) : Point2D
- public parentToLocal(parentBounds: Bounds) : Bounds
- public requestFocus() : Void
-
Requests that this
Node
get the input focus, and that thisNode
's top-level ancestor become the focused Window.Requests that this
Node
get the input focus, and that thisNode
's top-level ancestor become the focused Window. If this node is not part of a scene graph rooted in a stage that is visible and can accept input focus, then calls to request focus will not cause thisNode
to become focused.Profile: common
- public sceneToLocal(sceneX: Number, sceneY: Number) : Point2D
- public sceneToLocal(scenePoint: Point2D) : Point2D
-
Transforms a point from the coordinate space of the javafx.scene.Scene into the local coordinate space of this
Node
.Transforms a point from the coordinate space of the javafx.scene.Scene into the local coordinate space of this
Node
.-
Parameters
- scenePoint
-
Returns
- Point2D
Profile: common
- public sceneToLocal(sceneBounds: Bounds) : Bounds
-
Transforms a rectangle from the coordinate space of the javafx.scene.Scene into the local coordinate space of this
Node
.Transforms a rectangle from the coordinate space of the javafx.scene.Scene into the local coordinate space of this
Node
.-
Parameters
- sceneBounds
-
Returns
- Bounds
Profile: common
- public toBack() : Void
-
Moves this
Node
to the back of its sibling nodes in terms of z-order.Moves this
Node
to the back of its sibling nodes in terms of z-order. This is accomplished by moving thisNode
to the first position in its parent'scontent
sequence. This function has no effect if thisNode
is not part of a group.Profile: common
- public toFront() : Void
-
Moves this
Node
to the front of its sibling nodes in terms of z-order.Moves this
Node
to the front of its sibling nodes in terms of z-order. This is accomplished by moving thisNode
to the last position in its parent'scontent
sequence. This function has no effect if thisNode
is not part of a group.Profile: common
- public toString() : java.lang.String