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 someNodeof thisScenehas input focus and a key has been pressed.final ObjectProperty<EventHandler<? super KeyEvent>>Defines a function to be called when someNodeof thisScenehas input focus and a key has been released.final ObjectProperty<EventHandler<? super KeyEvent>>Defines a function to be called when someNodeof thisScenehas 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>TheWindowfor thisScenefinal ReadOnlyDoublePropertyThe horizontal location of thisSceneon theWindow.final ReadOnlyDoublePropertyThe vertical location of thisSceneon theWindow. -
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassA 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.voidfinal ObjectProperty<Cursor>Defines the mouse cursor for thisScene.protected voidfinal ObjectProperty<EventDispatcher>Specifies the event dispatcher for this scene.final ObjectProperty<Paint>Defines the background fill of thisScene.voidMoves the focus to a reasonable initial location.The scene's current focus owner node.Gets the list of accelerators for thisScene.final CursorGets the value of thecursorproperty.final EventDispatcherGets the value of theeventDispatcherproperty.final PaintgetFill()Gets the value of thefillproperty.final NodeGets the value of thefocusOwnerproperty.final EventHandler<? super KeyEvent>Gets the value of theonKeyPressedproperty.final EventHandler<? super KeyEvent>Gets the value of theonKeyReleasedproperty.final EventHandler<? super KeyEvent>Gets the value of theonKeyTypedproperty.final EventHandler<? super MouseEvent>Gets the value of theonMouseClickedproperty.final EventHandler<? super MouseEvent>Gets the value of theonMousePressedproperty.final EventHandler<? super MouseEvent>Gets the value of theonMouseReleasedproperty.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 WindowGets the value of thewindowproperty.final doublegetX()Gets the value of thexproperty.final doublegetY()Gets the value of theyproperty.booleanTests if Scene has properties.voidimpl_setWindow(Window value) booleanfinal ObjectProperty<EventHandler<? super KeyEvent>>Defines a function to be called when someNodeof thisScenehas input focus and a key has been pressed.final ObjectProperty<EventHandler<? super KeyEvent>>Defines a function to be called when someNodeof thisScenehas input focus and a key has been released.final ObjectProperty<EventHandler<? super KeyEvent>>Defines a function to be called when someNodeof thisScenehas 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 voidfinal voidSets the value of thecursorproperty.final voidSets the value of theeventDispatcherproperty.protected final <T extends Event>
voidsetEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler) Sets the handler to use for this event type.final voidSets the value of thefillproperty.final voidsetOnKeyPressed(EventHandler<? super KeyEvent> value) Sets the value of theonKeyPressedproperty.final voidsetOnKeyReleased(EventHandler<? super KeyEvent> value) Sets the value of theonKeyReleasedproperty.final voidsetOnKeyTyped(EventHandler<? super KeyEvent> value) Sets the value of theonKeyTypedproperty.final voidsetOnMouseClicked(EventHandler<? super MouseEvent> value) Sets the value of theonMouseClickedproperty.final voidsetOnMousePressed(EventHandler<? super MouseEvent> value) Sets the value of theonMousePressedproperty.final voidsetOnMouseReleased(EventHandler<? super MouseEvent> value) Sets the value of theonMouseReleasedproperty.voidsetUserData(Object value) Convenience method for setting a single Object property that can be retrieved at a later date.voidvoidvoidupdateChildrenPeers(Collection<Node> nodes) final ReadOnlyProperty<Window>TheWindowfor thisScenefinal ReadOnlyDoublePropertyThe horizontal location of thisSceneon theWindow.final ReadOnlyDoublePropertyThe vertical location of thisSceneon theWindow.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasHeightProperty
getHeight, setHeightMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasRootProperty
getRoot, setRootMethods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasWidthProperty
getWidth, setWidth
-
Property Details
-
width
- Specified by:
widthPropertyin interfaceHasWidthProperty- Returns:
- the
widthproperty - See Also:
-
height
- Specified by:
heightPropertyin interfaceHasHeightProperty- Returns:
- the
heightproperty - See Also:
-
fill
Defines the background fill of thisScene. Both anullvalue meaning 'paint no background' and aPaintwith 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 nodeof theScene, as it typically is stretched to take up all available space in theScene. The root node of theSceneis 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:
fillPropertyin interfaceHasFillProperty- Default value:
- WHITE
- Returns:
- the
fillproperty - See Also:
-
x
The horizontal location of thisSceneon theWindow.- See Also:
-
y
The vertical location of thisSceneon theWindow.- See Also:
-
root
- Specified by:
rootPropertyin interfaceHasRootProperty- Returns:
- the
rootproperty - See Also:
-
window
TheWindowfor 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 someNodeof thisScenehas 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 someNodeof thisScenehas 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 someNodeof thisScenehas 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:
widthPropertyin interfaceHasWidthProperty- Returns:
- the
widthproperty - See Also:
-
heightProperty
- Specified by:
heightPropertyin interfaceHasHeightProperty- Returns:
- the
heightproperty - See Also:
-
setFill
Sets the value of thefillproperty.- Specified by:
setFillin interfaceHasFillProperty- Property description:
- Defines the background fill of this
Scene. Both anullvalue meaning 'paint no background' and aPaintwith 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 nodeof theScene, as it typically is stretched to take up all available space in theScene. The root node of theSceneis 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 thefillproperty- See Also:
-
getFill
Gets the value of thefillproperty.- Specified by:
getFillin interfaceHasFillProperty- Property description:
- Defines the background fill of this
Scene. Both anullvalue meaning 'paint no background' and aPaintwith 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 nodeof theScene, as it typically is stretched to take up all available space in theScene. The root node of theSceneis 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
fillproperty - See Also:
-
fillProperty
Defines the background fill of thisScene. Both anullvalue meaning 'paint no background' and aPaintwith 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 nodeof theScene, as it typically is stretched to take up all available space in theScene. The root node of theSceneis 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:
fillPropertyin interfaceHasFillProperty- Default value:
- WHITE
- Returns:
- the
fillproperty - See Also:
-
getX
public final double getX()Gets the value of thexproperty.- Property description:
- The horizontal location of this
Sceneon theWindow. - Returns:
- the value of the
xproperty - See Also:
-
xProperty
The horizontal location of thisSceneon theWindow.- Returns:
- the
xproperty - See Also:
-
getY
public final double getY()Gets the value of theyproperty.- Property description:
- The vertical location of this
Sceneon theWindow. - Returns:
- the value of the
yproperty - See Also:
-
yProperty
The vertical location of thisSceneon theWindow.- Returns:
- the
yproperty - See Also:
-
rootProperty
- Specified by:
rootPropertyin interfaceHasRootProperty- Returns:
- the
rootproperty - See Also:
-
getWindow
Gets the value of thewindowproperty.- Property description:
- The
Windowfor thisScene - Returns:
- the value of the
windowproperty - See Also:
-
windowProperty
TheWindowfor thisScene- Returns:
- the
windowproperty - See Also:
-
impl_setWindow
-
resizeRootToPreferredSize
-
getFocusOwner
Gets the value of thefocusOwnerproperty.- 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
focusOwnerproperty - 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
focusOwnerproperty - Since:
- JavaFX 2.2
- See Also:
-
getAccelerators
Gets the list of accelerators for thisScene.- Returns:
- the list of accelerators
-
setCursor
Sets the value of thecursorproperty.- Property description:
- Defines the mouse cursor for this
Scene. - Parameters:
value- the value for thecursorproperty- See Also:
-
getCursor
Gets the value of thecursorproperty.- Property description:
- Defines the mouse cursor for this
Scene. - Returns:
- the value of the
cursorproperty - See Also:
-
cursorProperty
Defines the mouse cursor for thisScene.- Returns:
- the
cursorproperty - See Also:
-
setEventDispatcher
Sets the value of theeventDispatcherproperty.- 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 theeventDispatcherproperty- See Also:
-
getEventDispatcher
Gets the value of theeventDispatcherproperty.- 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
eventDispatcherproperty - 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
eventDispatcherproperty - 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:
buildEventDispatchChainin 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 theonMouseClickedproperty.- 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 theonMouseClickedproperty- See Also:
-
getOnMouseClicked
Gets the value of theonMouseClickedproperty.- 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
onMouseClickedproperty - See Also:
-
onMouseClickedProperty
Defines a function to be called when a mouse button has been clicked (pressed and released) on thisScene.- Returns:
- the
onMouseClickedproperty - See Also:
-
setOnMousePressed
Sets the value of theonMousePressedproperty.- Property description:
- Defines a function to be called when a mouse button
has been pressed on this
Scene. - Parameters:
value- the value for theonMousePressedproperty- See Also:
-
getOnMousePressed
Gets the value of theonMousePressedproperty.- Property description:
- Defines a function to be called when a mouse button
has been pressed on this
Scene. - Returns:
- the value of the
onMousePressedproperty - See Also:
-
onMousePressedProperty
Defines a function to be called when a mouse button has been pressed on thisScene.- Returns:
- the
onMousePressedproperty - See Also:
-
setOnMouseReleased
Sets the value of theonMouseReleasedproperty.- Property description:
- Defines a function to be called when a mouse button
has been released on this
Scene. - Parameters:
value- the value for theonMouseReleasedproperty- See Also:
-
getOnMouseReleased
Gets the value of theonMouseReleasedproperty.- Property description:
- Defines a function to be called when a mouse button
has been released on this
Scene. - Returns:
- the value of the
onMouseReleasedproperty - See Also:
-
onMouseReleasedProperty
Defines a function to be called when a mouse button has been released on thisScene.- Returns:
- the
onMouseReleasedproperty - 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 theonKeyPressedproperty.- Property description:
- Defines a function to be called when some
Nodeof thisScenehas 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 theonKeyPressedproperty- See Also:
-
getOnKeyPressed
Gets the value of theonKeyPressedproperty.- Property description:
- Defines a function to be called when some
Nodeof thisScenehas 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
onKeyPressedproperty - See Also:
-
onKeyPressedProperty
Defines a function to be called when someNodeof thisScenehas 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
onKeyPressedproperty - See Also:
-
setOnKeyReleased
Sets the value of theonKeyReleasedproperty.- Property description:
- Defines a function to be called when some
Nodeof thisScenehas 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 theonKeyReleasedproperty- See Also:
-
getOnKeyReleased
Gets the value of theonKeyReleasedproperty.- Property description:
- Defines a function to be called when some
Nodeof thisScenehas 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
onKeyReleasedproperty - See Also:
-
onKeyReleasedProperty
Defines a function to be called when someNodeof thisScenehas 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
onKeyReleasedproperty - See Also:
-
setOnKeyTyped
Sets the value of theonKeyTypedproperty.- Property description:
- Defines a function to be called when some
Nodeof thisScenehas 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 theonKeyTypedproperty- See Also:
-
getOnKeyTyped
Gets the value of theonKeyTypedproperty.- Property description:
- Defines a function to be called when some
Nodeof thisScenehas 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
onKeyTypedproperty - See Also:
-
onKeyTypedProperty
Defines a function to be called when someNodeof thisScenehas 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
onKeyTypedproperty - 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 anEventof 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 anEventof 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.
-