Package javafx.scene
Class Scene
java.lang.Object
javafx.scene.Scene
- All Implemented Interfaces:
HasFillProperty
,HasHeightProperty
,HasRootProperty
,HasWidthProperty
,EventTarget
public class Scene
extends Object
implements EventTarget, HasRootProperty, HasWidthProperty, HasHeightProperty, HasFillProperty
- Author:
- Bruno Salmon
-
Property Summary
PropertiesTypePropertyDescriptionfinal ObjectProperty<Cursor>
Defines the mouse cursor for thisScene
.final ObjectProperty<EventDispatcher>
Specifies the event dispatcher for this scene.final ObjectProperty<Paint>
Defines the background fill of thisScene
.The scene's current focus owner node.final ObjectProperty<EventHandler<? super KeyEvent>>
Defines a function to be called when someNode
of thisScene
has input focus and a key has been pressed.final ObjectProperty<EventHandler<? super KeyEvent>>
Defines a function to be called when someNode
of thisScene
has input focus and a key has been released.final ObjectProperty<EventHandler<? super KeyEvent>>
Defines a function to be called when someNode
of thisScene
has input focus and a key has been typed.final ObjectProperty<EventHandler<? super MouseEvent>>
Defines a function to be called when a mouse button has been clicked (pressed and released) on thisScene
.final ObjectProperty<EventHandler<? super MouseEvent>>
Defines a function to be called when a mouse button has been pressed on thisScene
.final ObjectProperty<EventHandler<? super MouseEvent>>
Defines a function to be called when a mouse button has been released on thisScene
.final ReadOnlyProperty<Window>
TheWindow
for thisScene
final ReadOnlyDoubleProperty
The horizontal location of thisScene
on theWindow
.final ReadOnlyDoubleProperty
The vertical location of thisScene
on theWindow
. -
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
A Drag and Drop gesture has a lifespan that lasts from mouse PRESSED event to mouse RELEASED event. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <T extends Event>
voidaddEventFilter
(EventType<T> eventType, EventHandler<? super T> eventFilter) Registers an event filter to this scene.final <T extends Event>
voidaddEventHandler
(EventType<T> eventType, EventHandler<? super T> eventHandler) Registers an event handler to this scene.Construct an event dispatch chain for this scene.void
final ObjectProperty<Cursor>
Defines the mouse cursor for thisScene
.protected void
final ObjectProperty<EventDispatcher>
Specifies the event dispatcher for this scene.final ObjectProperty<Paint>
Defines the background fill of thisScene
.void
Moves the focus to a reasonable initial location.The scene's current focus owner node.Gets the list of accelerators for thisScene
.final Cursor
Gets the value of thecursor
property.final EventDispatcher
Gets the value of theeventDispatcher
property.final Paint
getFill()
Gets the value of thefill
property.final Node
Gets the value of thefocusOwner
property.final EventHandler<? super KeyEvent>
Gets the value of theonKeyPressed
property.final EventHandler<? super KeyEvent>
Gets the value of theonKeyReleased
property.final EventHandler<? super KeyEvent>
Gets the value of theonKeyTyped
property.final EventHandler<? super MouseEvent>
Gets the value of theonMouseClicked
property.final EventHandler<? super MouseEvent>
Gets the value of theonMousePressed
property.final EventHandler<? super MouseEvent>
Gets the value of theonMouseReleased
property.final ObservableMap<Object,
Object> Returns an observable map of properties on this node for use primarily by application developers.final ObservableList<String>
Gets an observable list of string URLs linking to the stylesheets to use with this scene's contents.Returns a previously set Object property, or null if no such property has been set using thesetUserData(java.lang.Object)
method.final Window
Gets the value of thewindow
property.final double
getX()
Gets the value of thex
property.final double
getY()
Gets the value of they
property.boolean
Tests if Scene has properties.void
impl_setWindow
(Window value) boolean
final ObjectProperty<EventHandler<? super KeyEvent>>
Defines a function to be called when someNode
of thisScene
has input focus and a key has been pressed.final ObjectProperty<EventHandler<? super KeyEvent>>
Defines a function to be called when someNode
of thisScene
has input focus and a key has been released.final ObjectProperty<EventHandler<? super KeyEvent>>
Defines a function to be called when someNode
of thisScene
has input focus and a key has been typed.final ObjectProperty<EventHandler<? super MouseEvent>>
Defines a function to be called when a mouse button has been clicked (pressed and released) on thisScene
.final ObjectProperty<EventHandler<? super MouseEvent>>
Defines a function to be called when a mouse button has been pressed on thisScene
.final ObjectProperty<EventHandler<? super MouseEvent>>
Defines a function to be called when a mouse button has been released on thisScene
.final <T extends Event>
voidremoveEventFilter
(EventType<T> eventType, EventHandler<? super T> eventFilter) Unregisters a previously registered event filter from this scene.final <T extends Event>
voidremoveEventHandler
(EventType<T> eventType, EventHandler<? super T> eventHandler) Unregisters a previously registered event handler from this scene.final void
final void
Sets the value of thecursor
property.final void
Sets the value of theeventDispatcher
property.protected final <T extends Event>
voidsetEventHandler
(EventType<T> eventType, EventHandler<? super T> eventHandler) Sets the handler to use for this event type.final void
Sets the value of thefill
property.final void
setOnKeyPressed
(EventHandler<? super KeyEvent> value) Sets the value of theonKeyPressed
property.final void
setOnKeyReleased
(EventHandler<? super KeyEvent> value) Sets the value of theonKeyReleased
property.final void
setOnKeyTyped
(EventHandler<? super KeyEvent> value) Sets the value of theonKeyTyped
property.final void
setOnMouseClicked
(EventHandler<? super MouseEvent> value) Sets the value of theonMouseClicked
property.final void
setOnMousePressed
(EventHandler<? super MouseEvent> value) Sets the value of theonMousePressed
property.final void
setOnMouseReleased
(EventHandler<? super MouseEvent> value) Sets the value of theonMouseReleased
property.void
setUserData
(Object value) Convenience method for setting a single Object property that can be retrieved at a later date.void
void
void
updateChildrenPeers
(Collection<Node> nodes) final ReadOnlyProperty<Window>
TheWindow
for thisScene
final ReadOnlyDoubleProperty
The horizontal location of thisScene
on theWindow
.final ReadOnlyDoubleProperty
The vertical location of thisScene
on theWindow
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasHeightProperty
getHeight, setHeight
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasRootProperty
getRoot, setRoot
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasWidthProperty
getWidth, setWidth
-
Property Details
-
width
- Specified by:
widthProperty
in interfaceHasWidthProperty
- Returns:
- the
width
property - See Also:
-
height
- Specified by:
heightProperty
in interfaceHasHeightProperty
- Returns:
- the
height
property - See Also:
-
fill
Defines the background fill of thisScene
. Both anull
value meaning 'paint no background' and aPaint
with transparency are supported. The default fill of the Scene isColor.WHITE
, but it is more commonly the case that the initial color shown to users is the background fill of theroot node
of theScene
, as it typically is stretched to take up all available space in theScene
. The root node of theScene
is given the CSS style class 'root', and the default user agent stylesheets that ship with JavaFX (presently Caspian and Modena) apply styling on to this root style class. In the case of Caspian this does not impact the background fill color of the root node, but in the case of Modena the default fill is set to be a light gray color.- Specified by:
fillProperty
in interfaceHasFillProperty
- Default value:
- WHITE
- Returns:
- the
fill
property - See Also:
-
x
The horizontal location of thisScene
on theWindow
.- See Also:
-
y
The vertical location of thisScene
on theWindow
.- See Also:
-
root
- Specified by:
rootProperty
in interfaceHasRootProperty
- Returns:
- the
root
property - See Also:
-
window
TheWindow
for thisScene
- See Also:
-
focusOwner
The scene's current focus owner node. This node's "focused" variable might be false if this scene has no window, or if the window is inactive (window.focused == false).- Since:
- JavaFX 2.2
- See Also:
-
cursor
Defines the mouse cursor for thisScene
.- See Also:
-
eventDispatcher
Specifies the event dispatcher for this scene. When replacing the value with a newEventDispatcher
, the new dispatcher should forward events to the replaced dispatcher to keep the scene's default event handling behavior. -
onMouseClicked
Defines a function to be called when a mouse button has been clicked (pressed and released) on thisScene
. -
onMousePressed
Defines a function to be called when a mouse button has been pressed on thisScene
. -
onMouseReleased
Defines a function to be called when a mouse button has been released on thisScene
. -
onKeyPressed
Defines a function to be called when someNode
of thisScene
has input focus and a key has been pressed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. -
onKeyReleased
Defines a function to be called when someNode
of thisScene
has input focus and a key has been released. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. -
onKeyTyped
Defines a function to be called when someNode
of thisScene
has input focus and a key has been typed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase.
-
-
Constructor Details
-
Scene
-
Scene
-
Scene
-
Scene
-
-
Method Details
-
widthProperty
- Specified by:
widthProperty
in interfaceHasWidthProperty
- Returns:
- the
width
property - See Also:
-
heightProperty
- Specified by:
heightProperty
in interfaceHasHeightProperty
- Returns:
- the
height
property - See Also:
-
setFill
Sets the value of thefill
property.- Specified by:
setFill
in interfaceHasFillProperty
- Property description:
- Defines the background fill of this
Scene
. Both anull
value meaning 'paint no background' and aPaint
with transparency are supported. The default fill of the Scene isColor.WHITE
, but it is more commonly the case that the initial color shown to users is the background fill of theroot node
of theScene
, as it typically is stretched to take up all available space in theScene
. The root node of theScene
is given the CSS style class 'root', and the default user agent stylesheets that ship with JavaFX (presently Caspian and Modena) apply styling on to this root style class. In the case of Caspian this does not impact the background fill color of the root node, but in the case of Modena the default fill is set to be a light gray color. - Default value:
- WHITE
- Parameters:
value
- the value for thefill
property- See Also:
-
getFill
Gets the value of thefill
property.- Specified by:
getFill
in interfaceHasFillProperty
- Property description:
- Defines the background fill of this
Scene
. Both anull
value meaning 'paint no background' and aPaint
with transparency are supported. The default fill of the Scene isColor.WHITE
, but it is more commonly the case that the initial color shown to users is the background fill of theroot node
of theScene
, as it typically is stretched to take up all available space in theScene
. The root node of theScene
is given the CSS style class 'root', and the default user agent stylesheets that ship with JavaFX (presently Caspian and Modena) apply styling on to this root style class. In the case of Caspian this does not impact the background fill color of the root node, but in the case of Modena the default fill is set to be a light gray color. - Default value:
- WHITE
- Returns:
- the value of the
fill
property - See Also:
-
fillProperty
Defines the background fill of thisScene
. Both anull
value meaning 'paint no background' and aPaint
with transparency are supported. The default fill of the Scene isColor.WHITE
, but it is more commonly the case that the initial color shown to users is the background fill of theroot node
of theScene
, as it typically is stretched to take up all available space in theScene
. The root node of theScene
is given the CSS style class 'root', and the default user agent stylesheets that ship with JavaFX (presently Caspian and Modena) apply styling on to this root style class. In the case of Caspian this does not impact the background fill color of the root node, but in the case of Modena the default fill is set to be a light gray color.- Specified by:
fillProperty
in interfaceHasFillProperty
- Default value:
- WHITE
- Returns:
- the
fill
property - See Also:
-
getX
public final double getX()Gets the value of thex
property.- Property description:
- The horizontal location of this
Scene
on theWindow
. - Returns:
- the value of the
x
property - See Also:
-
xProperty
The horizontal location of thisScene
on theWindow
.- Returns:
- the
x
property - See Also:
-
getY
public final double getY()Gets the value of they
property.- Property description:
- The vertical location of this
Scene
on theWindow
. - Returns:
- the value of the
y
property - See Also:
-
yProperty
The vertical location of thisScene
on theWindow
.- Returns:
- the
y
property - See Also:
-
rootProperty
- Specified by:
rootProperty
in interfaceHasRootProperty
- Returns:
- the
root
property - See Also:
-
getWindow
Gets the value of thewindow
property.- Property description:
- The
Window
for thisScene
- Returns:
- the value of the
window
property - See Also:
-
windowProperty
TheWindow
for thisScene
- Returns:
- the
window
property - See Also:
-
impl_setWindow
-
resizeRootToPreferredSize
-
getFocusOwner
Gets the value of thefocusOwner
property.- Property description:
- The scene's current focus owner node. This node's "focused" variable might be false if this scene has no window, or if the window is inactive (window.focused == false).
- Returns:
- the value of the
focusOwner
property - Since:
- JavaFX 2.2
- See Also:
-
focusOwnerProperty
The scene's current focus owner node. This node's "focused" variable might be false if this scene has no window, or if the window is inactive (window.focused == false).- Returns:
- the
focusOwner
property - Since:
- JavaFX 2.2
- See Also:
-
getAccelerators
Gets the list of accelerators for thisScene
.- Returns:
- the list of accelerators
-
setCursor
Sets the value of thecursor
property.- Property description:
- Defines the mouse cursor for this
Scene
. - Parameters:
value
- the value for thecursor
property- See Also:
-
getCursor
Gets the value of thecursor
property.- Property description:
- Defines the mouse cursor for this
Scene
. - Returns:
- the value of the
cursor
property - See Also:
-
cursorProperty
Defines the mouse cursor for thisScene
.- Returns:
- the
cursor
property - See Also:
-
setEventDispatcher
Sets the value of theeventDispatcher
property.- Property description:
- Specifies the event dispatcher for this scene. When replacing the value
with a new
EventDispatcher
, the new dispatcher should forward events to the replaced dispatcher to keep the scene's default event handling behavior. - Parameters:
value
- the value for theeventDispatcher
property- See Also:
-
getEventDispatcher
Gets the value of theeventDispatcher
property.- Property description:
- Specifies the event dispatcher for this scene. When replacing the value
with a new
EventDispatcher
, the new dispatcher should forward events to the replaced dispatcher to keep the scene's default event handling behavior. - Returns:
- the value of the
eventDispatcher
property - See Also:
-
eventDispatcherProperty
Specifies the event dispatcher for this scene. When replacing the value with a newEventDispatcher
, the new dispatcher should forward events to the replaced dispatcher to keep the scene's default event handling behavior.- Returns:
- the
eventDispatcher
property - See Also:
-
buildEventDispatchChain
Construct an event dispatch chain for this scene. The event dispatch chain contains all event dispatchers from the stage to this scene.- Specified by:
buildEventDispatchChain
in interfaceEventTarget
- Parameters:
tail
- the initial chain to build from- Returns:
- the resulting event dispatch chain for this scene
-
getProperties
Returns an observable map of properties on this node for use primarily by application developers.- Returns:
- an observable map of properties on this node for use primarily by application developers
- Since:
- JavaFX 8u40
-
hasProperties
public boolean hasProperties()Tests if Scene has properties.- Returns:
- true if node has properties.
- Since:
- JavaFX 8u40
-
setUserData
Convenience method for setting a single Object property that can be retrieved at a later date. This is functionally equivalent to calling the getProperties().put(Object key, Object value) method. This can later be retrieved by callinggetUserData()
.- Parameters:
value
- The value to be stored - this can later be retrieved by callinggetUserData()
.- Since:
- JavaFX 8u40
-
getUserData
Returns a previously set Object property, or null if no such property has been set using thesetUserData(java.lang.Object)
method.- Returns:
- The Object that was previously set, or null if no property has been set or if null was set.
- Since:
- JavaFX 8u40
-
getSceneRequester
-
updateChildrenPeers
-
getOrCreateAndBindNodePeer
-
isPulseRunning
public boolean isPulseRunning() -
startPulse
public void startPulse() -
stopPulse
public void stopPulse() -
doLayoutPass
protected void doLayoutPass() -
getOrCreateDndGesture
-
clearDndGesture
public void clearDndGesture() -
setOnMouseClicked
Sets the value of theonMouseClicked
property.- Property description:
- Defines a function to be called when a mouse button has been clicked
(pressed and released) on this
Scene
. - Parameters:
value
- the value for theonMouseClicked
property- See Also:
-
getOnMouseClicked
Gets the value of theonMouseClicked
property.- Property description:
- Defines a function to be called when a mouse button has been clicked
(pressed and released) on this
Scene
. - Returns:
- the value of the
onMouseClicked
property - See Also:
-
onMouseClickedProperty
Defines a function to be called when a mouse button has been clicked (pressed and released) on thisScene
.- Returns:
- the
onMouseClicked
property - See Also:
-
setOnMousePressed
Sets the value of theonMousePressed
property.- Property description:
- Defines a function to be called when a mouse button
has been pressed on this
Scene
. - Parameters:
value
- the value for theonMousePressed
property- See Also:
-
getOnMousePressed
Gets the value of theonMousePressed
property.- Property description:
- Defines a function to be called when a mouse button
has been pressed on this
Scene
. - Returns:
- the value of the
onMousePressed
property - See Also:
-
onMousePressedProperty
Defines a function to be called when a mouse button has been pressed on thisScene
.- Returns:
- the
onMousePressed
property - See Also:
-
setOnMouseReleased
Sets the value of theonMouseReleased
property.- Property description:
- Defines a function to be called when a mouse button
has been released on this
Scene
. - Parameters:
value
- the value for theonMouseReleased
property- See Also:
-
getOnMouseReleased
Gets the value of theonMouseReleased
property.- Property description:
- Defines a function to be called when a mouse button
has been released on this
Scene
. - Returns:
- the value of the
onMouseReleased
property - See Also:
-
onMouseReleasedProperty
Defines a function to be called when a mouse button has been released on thisScene
.- Returns:
- the
onMouseReleased
property - See Also:
-
getStylesheets
Gets an observable list of string URLs linking to the stylesheets to use with this scene's contents.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.
For additional information about using CSS with the scene graph, see the CSS Reference Guide.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); } }
- Returns:
- the list of stylesheets to use with this scene
-
setOnKeyPressed
Sets the value of theonKeyPressed
property.- Property description:
- Defines a function to be called when some
Node
of thisScene
has input focus and a key has been pressed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. - Parameters:
value
- the value for theonKeyPressed
property- See Also:
-
getOnKeyPressed
Gets the value of theonKeyPressed
property.- Property description:
- Defines a function to be called when some
Node
of thisScene
has input focus and a key has been pressed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. - Returns:
- the value of the
onKeyPressed
property - See Also:
-
onKeyPressedProperty
Defines a function to be called when someNode
of thisScene
has input focus and a key has been pressed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase.- Returns:
- the
onKeyPressed
property - See Also:
-
setOnKeyReleased
Sets the value of theonKeyReleased
property.- Property description:
- Defines a function to be called when some
Node
of thisScene
has input focus and a key has been released. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. - Parameters:
value
- the value for theonKeyReleased
property- See Also:
-
getOnKeyReleased
Gets the value of theonKeyReleased
property.- Property description:
- Defines a function to be called when some
Node
of thisScene
has input focus and a key has been released. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. - Returns:
- the value of the
onKeyReleased
property - See Also:
-
onKeyReleasedProperty
Defines a function to be called when someNode
of thisScene
has input focus and a key has been released. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase.- Returns:
- the
onKeyReleased
property - See Also:
-
setOnKeyTyped
Sets the value of theonKeyTyped
property.- Property description:
- Defines a function to be called when some
Node
of thisScene
has input focus and a key has been typed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. - Parameters:
value
- the value for theonKeyTyped
property- See Also:
-
getOnKeyTyped
Gets the value of theonKeyTyped
property.- Property description:
- Defines a function to be called when some
Node
of thisScene
has input focus and a key has been typed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase. - Returns:
- the value of the
onKeyTyped
property - See Also:
-
onKeyTypedProperty
Defines a function to be called when someNode
of thisScene
has input focus and a key has been typed. The function is called only if the event hasn't been already consumed during its capturing or bubbling phase.- Returns:
- the
onKeyTyped
property - See Also:
-
addEventHandler
public final <T extends Event> void addEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler) Registers an event handler to this scene. The handler is called when the scene receives anEvent
of the specified type during the bubbling phase of event delivery.- Type Parameters:
T
- the specific event class of the handler- Parameters:
eventType
- the type of the events to receive by the handlereventHandler
- the handler to register- Throws:
NullPointerException
- if the event type or handler is null
-
removeEventHandler
public final <T extends Event> void removeEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler) Unregisters a previously registered event handler from this scene. One handler might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the handler.- Type Parameters:
T
- the specific event class of the handler- Parameters:
eventType
- the event type from which to unregistereventHandler
- the handler to unregister- Throws:
NullPointerException
- if the event type or handler is null
-
addEventFilter
public final <T extends Event> void addEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter) Registers an event filter to this scene. The filter is called when the scene receives anEvent
of the specified type during the capturing phase of event delivery.- Type Parameters:
T
- the specific event class of the filter- Parameters:
eventType
- the type of the events to receive by the filtereventFilter
- the filter to register- Throws:
NullPointerException
- if the event type or filter is null
-
removeEventFilter
public final <T extends Event> void removeEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter) Unregisters a previously registered event filter from this scene. One filter might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the filter.- Type Parameters:
T
- the specific event class of the filter- Parameters:
eventType
- the event type from which to unregistereventFilter
- the filter to unregister- Throws:
NullPointerException
- if the event type or filter is null
-
setEventHandler
protected final <T extends Event> void setEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler) Sets the handler to use for this event type. There can only be one such handler specified at a time. This handler is guaranteed to be called first. This is used for registering the user-defined onFoo event handlers.- Type Parameters:
T
- the specific event class of the handler- Parameters:
eventType
- the event type to associate with the given eventHandlereventHandler
- the handler to register, or null to unregister- Throws:
NullPointerException
- if the event type is null
-
focusInitial
public void focusInitial()Moves the focus to a reasonable initial location. Called when a scene's focus is dirty and there's no current owner, or if the owner has been removed from the scene.
-