@DefaultProperty(value="root") public class Scene extends Object implements EventTarget
Scene
class is the container for all content in a scene graph.
The background of the scene is filled as specified by the fill
property.
The application must specify the root Node
for the scene graph by setting
the root
property. If a Group
is used as the root, the
contents of the scene graph will be clipped by the scene's width and height and
changes to the scene's size (if user resizes the stage) will not alter the
layout of the scene graph. If a resizable node (layout Region
or
Control
is set as the root, then the root's size will track the
scene's size, causing the contents to be relayed out as necessary.
The scene's size may be initialized by the application during construction. If no size is specified, the scene will automatically compute its initial size based on the preferred size of its content. If only one dimension is specified, the other dimension is computed using the specified dimension, respecting content bias of a root.
An application may request depth buffer support or scene anti-aliasing
support at the creation of a Scene
. A scene with only 2D shapes and
without any 3D transforms does not need a depth buffer nor scene
anti-aliasing support. A scene containing 3D shapes or 2D shapes with 3D
transforms may use depth buffer support for proper depth sorted rendering; to
avoid depth fighting (also known as Z fighting), disable depth testing on 2D
shapes that have no 3D transforms. See
depthTest
for more information. A scene with
3D shapes may enable scene anti-aliasing to improve its rendering quality.
The depthBuffer and antiAliasing flags are conditional features. With the
respective default values of: false and SceneAntialiasing.DISABLED
.
See ConditionalFeature.SCENE3D
for more information.
A default headlight will be added to a scene that contains one or more
Shape3D
nodes, but no light nodes. This light source is a
Color.WHITE
PointLight
placed at the camera position.
Scene objects must be constructed and modified on the JavaFX Application Thread.
Example:
import javafx.scene.*; import javafx.scene.paint.*; import javafx.scene.shape.*; Group root = new Group(); Scene s = new Scene(root, 300, 300, Color.BLACK); Rectangle r = new Rectangle(25,25,250,250); r.setFill(Color.BLUE); root.getChildren().add(r);
Constructor and Description |
---|
Scene(Parent root)
Creates a Scene for a specific root Node.
|
Scene(Parent root,
double width,
double height)
Creates a Scene for a specific root Node with a specific size.
|
Scene(Parent root,
double width,
double height,
boolean depthBuffer)
Constructs a scene consisting of a root, with a dimension of width and
height, and specifies whether a depth buffer is created for this scene.
|
Scene(Parent root,
double width,
double height,
boolean depthBuffer,
SceneAntialiasing antiAliasing)
Constructs a scene consisting of a root, with a dimension of width and
height, specifies whether a depth buffer is created for this scene and
specifies whether scene anti-aliasing is requested.
|
Scene(Parent root,
double width,
double height,
Paint fill)
Creates a Scene for a specific root Node with a specific size and fill.
|
Scene(Parent root,
Paint fill)
Creates a Scene for a specific root Node with a fill.
|
public Scene(Parent root)
root
- The root node of the scene graphNullPointerException
- if root is nullpublic Scene(Parent root, double width, double height)
root
- The root node of the scene graphwidth
- The width of the sceneheight
- The height of the sceneNullPointerException
- if root is nullpublic Scene(Parent root, Paint fill)
root
- The parentfill
- The fillNullPointerException
- if root is nullpublic Scene(Parent root, double width, double height, Paint fill)
root
- The root node of the scene graphwidth
- The width of the sceneheight
- The height of the scenefill
- The fillNullPointerException
- if root is nullpublic Scene(Parent root, double width, double height, boolean depthBuffer)
A scene with only 2D shapes and without any 3D transforms does not need a
depth buffer. A scene containing 3D shapes or 2D shapes with 3D
transforms may use depth buffer support for proper depth sorted
rendering; to avoid depth fighting (also known as Z fighting), disable
depth testing on 2D shapes that have no 3D transforms. See
depthTest
for more information.
root
- The root node of the scene graphwidth
- The width of the sceneheight
- The height of the scenedepthBuffer
- The depth buffer flag
The depthBuffer flag is a conditional feature and its default value is
false. See
ConditionalFeature.SCENE3D
for more information.
NullPointerException
- if root is nullNode.setDepthTest(DepthTest)
public Scene(Parent root, double width, double height, boolean depthBuffer, SceneAntialiasing antiAliasing)
A scene with only 2D shapes and without any 3D transforms does not need a
depth buffer nor scene anti-aliasing support. A scene containing 3D
shapes or 2D shapes with 3D transforms may use depth buffer support for
proper depth sorted rendering; to avoid depth fighting (also known as Z
fighting), disable depth testing on 2D shapes that have no 3D transforms.
See depthTest
for more information. A
scene with 3D shapes may enable scene anti-aliasing to improve its
rendering quality.
A Scene can be created and modified on any thread until it is attached to a Window
that is showing
(Window.isShowing()
. This does not mean the Scene is thread-safe,
so manipulation from multiple threads at the same time is illegal, may lead to unexpected results and must be avoided.
root
- The root node of the scene graphwidth
- The width of the sceneheight
- The height of the scenedepthBuffer
- The depth buffer flagantiAliasing
- The scene anti-aliasing attribute. A value of
null
is treated as DISABLED.
The depthBuffer and antiAliasing are conditional features. With the
respective default values of: false and SceneAntialiasing.DISABLED
. See
ConditionalFeature.SCENE3D
for more information.
NullPointerException
- if root is nullNode.setDepthTest(DepthTest)
@Deprecated public static void impl_setAllowPGAccess(boolean flag)
@Deprecated public TKScene impl_getPeer()
@Deprecated public TKPulseListener impl_getScenePulseListener()
public final SceneAntialiasing getAntiAliasing()
SceneAntialiasing
for this Scene
.
Note: this is a conditional feature. See
ConditionalFeature.SCENE3D
and SceneAntialiasing
for more information.
public final Window getWindow()
public final ReadOnlyObjectProperty<Window> windowProperty()
@Deprecated public void impl_setWindow(Window value)
@Deprecated public void impl_initPeer()
@Deprecated public void impl_disposePeer()
public final double getX()
public final ReadOnlyDoubleProperty xProperty()
public final double getY()
public final ReadOnlyDoubleProperty yProperty()
public final double getWidth()
public final ReadOnlyDoubleProperty widthProperty()
public final double getHeight()
public final ReadOnlyDoubleProperty heightProperty()
public final void setCamera(Camera value)
public final Camera getCamera()
public final ObjectProperty<Camera> cameraProperty()
public final void setFill(Paint value)
public final Paint getFill()
public final ObjectProperty<Paint> fillProperty()
public final void setRoot(Parent value)
public final Parent getRoot()
public final ObjectProperty<Parent> rootProperty()
public WritableImage snapshot(WritableImage image)
Paint
of this scene. The nodes in the scene are then rendered to the image.
The point (0,0) in scene coordinates is mapped to (0,0) in the image.
If the image is smaller than the size of the scene, then the rendering
will be clipped by the image.
When taking a snapshot of a scene that is being animated, either explicitly by the application or implicitly (such as chart animation), the snapshot will be rendered based on the state of the scene graph at the moment the snapshot is taken and will not reflect any subsequent animation changes.
image
- the writable image that will be used to hold the rendered scene.
It may be null in which case a new WritableImage will be constructed.
If the image is non-null, the scene will be rendered into the
existing image.
In this case, the width and height of the image determine the area
that is rendered instead of the width and height of the scene.IllegalStateException
- if this method is called on a thread
other than the JavaFX Application Thread.public void snapshot(Callback<SnapshotResult,Void> callback, WritableImage image)
Paint
of this scene. The nodes in the scene are then rendered to the image.
The point (0,0) in scene coordinates is mapped to (0,0) in the image.
If the image is smaller than the size of the scene, then the rendering
will be clipped by the image.
This is an asynchronous call, which means that other events or animation might be processed before the scene is rendered. If any such events modify a node in the scene that modification will be reflected in the rendered image (as it will also be reflected in the frame rendered to the Stage).
When taking a snapshot of a scene that is being animated, either explicitly by the application or implicitly (such as chart animation), the snapshot will be rendered based on the state of the scene graph at the moment the snapshot is taken and will not reflect any subsequent animation changes.
callback
- a class whose call method will be called when the image
is ready. The SnapshotResult that is passed into the call method of
the callback will contain the rendered image and the source scene
that was rendered. The callback parameter must not be null.image
- the writable image that will be used to hold the rendered scene.
It may be null in which case a new WritableImage will be constructed.
If the image is non-null, the scene will be rendered into the
existing image.
In this case, the width and height of the image determine the area
that is rendered instead of the width and height of the scene.IllegalStateException
- if this method is called on a thread
other than the JavaFX Application Thread.NullPointerException
- if the callback parameter is null.public final void setCursor(Cursor value)
public final Cursor getCursor()
public final ObjectProperty<Cursor> cursorProperty()
public Node lookup(String selector)
selector
- The css selector to look upNode
in the scene which matches the CSS selector
,
or null
if none is found.public final ObservableList<String> getStylesheets()
The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.
package com.example.javafx.app;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class MyApp extends Application {
@Override public void start(Stage stage) {
Scene scene = new Scene(new Group());
scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
For additional information about using CSS with the scene graph,
see the CSS Reference Guide.public final ObjectProperty<String> userAgentStylesheetProperty()
getUserAgentStylesheet()
,
setUserAgentStylesheet(String)
public final String getUserAgentStylesheet()
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
public final void setUserAgentStylesheet(String url)
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
url
- The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL
does not have a [scheme:] component, the URL is considered to be the [path] component only.
Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to
the root of the application's classpath.public final boolean isDepthBuffer()
@Deprecated public void impl_preferredSize()
@Deprecated public void impl_processMouseEvent(MouseEvent e)
@Deprecated public void impl_processKeyEvent(KeyEvent e)
public final Node getFocusOwner()
public final ReadOnlyObjectProperty<Node> focusOwnerProperty()
@Deprecated public void impl_enableInputMethodEvents(boolean enable)
public final void setEventDispatcher(EventDispatcher value)
public final EventDispatcher getEventDispatcher()
public final ObjectProperty<EventDispatcher> eventDispatcherProperty()
public final <T extends Event> void addEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
Event
of the specified type during the bubbling
phase of event delivery.T
- the specific event class of the handlereventType
- the type of the events to receive by the handlereventHandler
- the handler to registerNullPointerException
- if the event type or handler is nullpublic final <T extends Event> void removeEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
T
- the specific event class of the handlereventType
- the event type from which to unregistereventHandler
- the handler to unregisterNullPointerException
- if the event type or handler is nullpublic final <T extends Event> void addEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)
Event
of the specified type during the
capturing phase of event delivery.T
- the specific event class of the filtereventType
- the type of the events to receive by the filtereventFilter
- the filter to registerNullPointerException
- if the event type or filter is nullpublic final <T extends Event> void removeEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)
T
- the specific event class of the filtereventType
- the event type from which to unregistereventFilter
- the filter to unregisterNullPointerException
- if the event type or filter is nullprotected final <T extends Event> void setEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
T
- the specific event class of the handlereventType
- the event type to associate with the given eventHandlereventHandler
- the handler to register, or null to unregisterNullPointerException
- if the event type is nullpublic void addMnemonic(Mnemonic m)
m
- The mnemonicpublic void removeMnemonic(Mnemonic m)
m
- The mnemonicpublic ObservableMap<KeyCombination,ObservableList<Mnemonic>> getMnemonics()
Scene
.public ObservableMap<KeyCombination,Runnable> getAccelerators()
Scene
.public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)
buildEventDispatchChain
in interface EventTarget
tail
- the initial chain to build frompublic final void setOnContextMenuRequested(EventHandler<? super ContextMenuEvent> value)
public final EventHandler<? super ContextMenuEvent> getOnContextMenuRequested()
public final ObjectProperty<EventHandler<? super ContextMenuEvent>> onContextMenuRequestedProperty()
public final void setOnMouseClicked(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMouseClicked()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseClickedProperty()
public final void setOnMouseDragged(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMouseDragged()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseDraggedProperty()
public final void setOnMouseEntered(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMouseEntered()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseEnteredProperty()
public final void setOnMouseExited(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMouseExited()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseExitedProperty()
public final void setOnMouseMoved(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMouseMoved()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseMovedProperty()
public final void setOnMousePressed(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMousePressed()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMousePressedProperty()
public final void setOnMouseReleased(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnMouseReleased()
public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseReleasedProperty()
public final void setOnDragDetected(EventHandler<? super MouseEvent> value)
public final EventHandler<? super MouseEvent> getOnDragDetected()
public final ObjectProperty<EventHandler<? super MouseEvent>> onDragDetectedProperty()
public final void setOnMouseDragOver(EventHandler<? super MouseDragEvent> value)
public final EventHandler<? super MouseDragEvent> getOnMouseDragOver()
public final ObjectProperty<EventHandler<? super MouseDragEvent>> onMouseDragOverProperty()
public final void setOnMouseDragReleased(EventHandler<? super MouseDragEvent> value)
public final EventHandler<? super MouseDragEvent> getOnMouseDragReleased()
public final ObjectProperty<EventHandler<? super MouseDragEvent>> onMouseDragReleasedProperty()
public final void setOnMouseDragEntered(EventHandler<? super MouseDragEvent> value)
public final EventHandler<? super MouseDragEvent> getOnMouseDragEntered()
public final ObjectProperty<EventHandler<? super MouseDragEvent>> onMouseDragEnteredProperty()
public final void setOnMouseDragExited(EventHandler<? super MouseDragEvent> value)
public final EventHandler<? super MouseDragEvent> getOnMouseDragExited()
public final ObjectProperty<EventHandler<? super MouseDragEvent>> onMouseDragExitedProperty()
public final void setOnScrollStarted(EventHandler<? super ScrollEvent> value)
public final EventHandler<? super ScrollEvent> getOnScrollStarted()
public final ObjectProperty<EventHandler<? super ScrollEvent>> onScrollStartedProperty()
public final void setOnScroll(EventHandler<? super ScrollEvent> value)
public final EventHandler<? super ScrollEvent> getOnScroll()
public final ObjectProperty<EventHandler<? super ScrollEvent>> onScrollProperty()
public final void setOnScrollFinished(EventHandler<? super ScrollEvent> value)
public final EventHandler<? super ScrollEvent> getOnScrollFinished()
public final ObjectProperty<EventHandler<? super ScrollEvent>> onScrollFinishedProperty()
public final void setOnRotationStarted(EventHandler<? super RotateEvent> value)
public final EventHandler<? super RotateEvent> getOnRotationStarted()
public final ObjectProperty<EventHandler<? super RotateEvent>> onRotationStartedProperty()
public final void setOnRotate(EventHandler<? super RotateEvent> value)
public final EventHandler<? super RotateEvent> getOnRotate()
public final ObjectProperty<EventHandler<? super RotateEvent>> onRotateProperty()
public final void setOnRotationFinished(EventHandler<? super RotateEvent> value)
public final EventHandler<? super RotateEvent> getOnRotationFinished()
public final ObjectProperty<EventHandler<? super RotateEvent>> onRotationFinishedProperty()
public final void setOnZoomStarted(EventHandler<? super ZoomEvent> value)
public final EventHandler<? super ZoomEvent> getOnZoomStarted()
public final ObjectProperty<EventHandler<? super ZoomEvent>> onZoomStartedProperty()
public final void setOnZoom(EventHandler<? super ZoomEvent> value)
public final EventHandler<? super ZoomEvent> getOnZoom()
public final ObjectProperty<EventHandler<? super ZoomEvent>> onZoomProperty()
public final void setOnZoomFinished(EventHandler<? super ZoomEvent> value)
public final EventHandler<? super ZoomEvent> getOnZoomFinished()
public final ObjectProperty<EventHandler<? super ZoomEvent>> onZoomFinishedProperty()
public final void setOnSwipeUp(EventHandler<? super SwipeEvent> value)
public final EventHandler<? super SwipeEvent> getOnSwipeUp()
public final ObjectProperty<EventHandler<? super SwipeEvent>> onSwipeUpProperty()
public final void setOnSwipeDown(EventHandler<? super SwipeEvent> value)
public final EventHandler<? super SwipeEvent> getOnSwipeDown()
public final ObjectProperty<EventHandler<? super SwipeEvent>> onSwipeDownProperty()
public final void setOnSwipeLeft(EventHandler<? super SwipeEvent> value)
public final EventHandler<? super SwipeEvent> getOnSwipeLeft()
public final ObjectProperty<EventHandler<? super SwipeEvent>> onSwipeLeftProperty()
public final void setOnSwipeRight(EventHandler<? super SwipeEvent> value)
public final EventHandler<? super SwipeEvent> getOnSwipeRight()
public final ObjectProperty<EventHandler<? super SwipeEvent>> onSwipeRightProperty()
public final void setOnTouchPressed(EventHandler<? super TouchEvent> value)
public final EventHandler<? super TouchEvent> getOnTouchPressed()
public final ObjectProperty<EventHandler<? super TouchEvent>> onTouchPressedProperty()
public final void setOnTouchMoved(EventHandler<? super TouchEvent> value)
public final EventHandler<? super TouchEvent> getOnTouchMoved()
public final ObjectProperty<EventHandler<? super TouchEvent>> onTouchMovedProperty()
public final void setOnTouchReleased(EventHandler<? super TouchEvent> value)
public final EventHandler<? super TouchEvent> getOnTouchReleased()
public final ObjectProperty<EventHandler<? super TouchEvent>> onTouchReleasedProperty()
public final void setOnTouchStationary(EventHandler<? super TouchEvent> value)
public final EventHandler<? super TouchEvent> getOnTouchStationary()
public final ObjectProperty<EventHandler<? super TouchEvent>> onTouchStationaryProperty()
public final void setOnDragEntered(EventHandler<? super DragEvent> value)
public final EventHandler<? super DragEvent> getOnDragEntered()
public final ObjectProperty<EventHandler<? super DragEvent>> onDragEnteredProperty()
Scene
.public final void setOnDragExited(EventHandler<? super DragEvent> value)
public final EventHandler<? super DragEvent> getOnDragExited()
public final ObjectProperty<EventHandler<? super DragEvent>> onDragExitedProperty()
Scene
.public final void setOnDragOver(EventHandler<? super DragEvent> value)
public final EventHandler<? super DragEvent> getOnDragOver()
public final ObjectProperty<EventHandler<? super DragEvent>> onDragOverProperty()
Scene
.public final void setOnDragDropped(EventHandler<? super DragEvent> value)
public final EventHandler<? super DragEvent> getOnDragDropped()
public final ObjectProperty<EventHandler<? super DragEvent>> onDragDroppedProperty()
public final void setOnDragDone(EventHandler<? super DragEvent> value)
public final EventHandler<? super DragEvent> getOnDragDone()
public final ObjectProperty<EventHandler<? super DragEvent>> onDragDoneProperty()
transferMode
of the
event shows what just happened at the drop target.
If transferMode
has the value MOVE
, then the source can
clear out its data. Clearing the source's data gives the appropriate
appearance to a user that the data has been moved by the drag and drop
gesture. A transferMode
that has the value NONE
indicates that no data was transferred during the drag and drop gesture.
Positional data for the DragEvent
is invalid. Valid positional
data for the DragEvent
is presented in the onDragDropped
event handler.public Dragboard startDragAndDrop(TransferMode... transferModes)
Scene
.
Can be called only from a DRAG_DETECTED event handler. The returned
Dragboard
is used to transfer data during
the drag and drop gesture. Placing this Scene
's data on the
Dragboard
also identifies this Scene
as the source of
the drag and drop gesture.
More detail about drag and drop gestures is described in the overivew
of DragEvent
.transferModes
- The supported TransferMode
(s) of this Node
Dragboard
to place this Scene
's data onIllegalStateException
- if drag and drop cannot be started at this
moment (it's called outside of DRAG_DETECTED
event handling).DragEvent
public void startFullDrag()
DRAG_DETECTED
mouse
event handler. More detail about dragging gestures can be found
in the overview of MouseEvent
and MouseDragEvent
.IllegalStateException
- if the full press-drag-release gesture
cannot be started at this moment (it's called outside of
DRAG_DETECTED
event handling).MouseEvent
,
MouseDragEvent
public final void setOnKeyPressed(EventHandler<? super KeyEvent> value)
public final EventHandler<? super KeyEvent> getOnKeyPressed()
public final ObjectProperty<EventHandler<? super KeyEvent>> onKeyPressedProperty()
public final void setOnKeyReleased(EventHandler<? super KeyEvent> value)
public final EventHandler<? super KeyEvent> getOnKeyReleased()
public final ObjectProperty<EventHandler<? super KeyEvent>> onKeyReleasedProperty()
public final void setOnKeyTyped(EventHandler<? super KeyEvent> value)
public final EventHandler<? super KeyEvent> getOnKeyTyped()
public final ObjectProperty<EventHandler<? super KeyEvent>> onKeyTypedProperty()
public final void setOnInputMethodTextChanged(EventHandler<? super InputMethodEvent> value)
public final EventHandler<? super InputMethodEvent> getOnInputMethodTextChanged()
public final ObjectProperty<EventHandler<? super InputMethodEvent>> onInputMethodTextChangedProperty()
public final ObservableMap<Object,Object> getProperties()
public boolean hasProperties()
public void setUserData(Object value)
getUserData()
.value
- The value to be stored - this can later be retrieved by calling
getUserData()
.public Object getUserData()
setUserData(java.lang.Object)
method.public final void setNodeOrientation(NodeOrientation orientation)
public final NodeOrientation getNodeOrientation()
public final ObjectProperty<NodeOrientation> nodeOrientationProperty()
Node orientation describes the flow of visual data within a node. In the English speaking world, visual data normally flows from left-to-right. In an Arabic or Hebrew world, visual data flows from right-to-left. This is consistent with the reading order of text in both worlds. The default value is left-to-right.
public final NodeOrientation getEffectiveNodeOrientation()
public final ReadOnlyObjectProperty<NodeOrientation> effectiveNodeOrientationProperty()
Copyright © 2020. All rights reserved.