Package javafx.scene

Class Scene

java.lang.Object
javafx.scene.Scene
All Implemented Interfaces:
HasFillProperty, HasHeightProperty, HasRootProperty, HasWidthProperty, EventTarget

Author:
Bruno Salmon
  • Property Details

  • Constructor Details

    • Scene

      public Scene(Parent root)
    • Scene

      public Scene(Parent root, double width, double height)
    • Scene

      public Scene(Parent root, Paint fill)
    • Scene

      public Scene(Parent root, double width, double height, Paint fill)
  • Method Details

    • widthProperty

      public DoubleProperty widthProperty()
      Specified by:
      widthProperty in interface HasWidthProperty
      Returns:
      the width property
      See Also:
    • heightProperty

      public DoubleProperty heightProperty()
      Specified by:
      heightProperty in interface HasHeightProperty
      Returns:
      the height property
      See Also:
    • setFill

      public final void setFill(Paint value)
      Sets the value of the fill property.
      Specified by:
      setFill in interface HasFillProperty
      Property description:
      Defines the background fill of this Scene. Both a null value meaning 'paint no background' and a Paint with transparency are supported. The default fill of the Scene is Color.WHITE, but it is more commonly the case that the initial color shown to users is the background fill of the root node of the Scene, as it typically is stretched to take up all available space in the Scene. The root node of the Scene 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 the fill property
      See Also:
    • getFill

      public final Paint getFill()
      Gets the value of the fill property.
      Specified by:
      getFill in interface HasFillProperty
      Property description:
      Defines the background fill of this Scene. Both a null value meaning 'paint no background' and a Paint with transparency are supported. The default fill of the Scene is Color.WHITE, but it is more commonly the case that the initial color shown to users is the background fill of the root node of the Scene, as it typically is stretched to take up all available space in the Scene. The root node of the Scene 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

      public final ObjectProperty<Paint> fillProperty()
      Defines the background fill of this Scene. Both a null value meaning 'paint no background' and a Paint with transparency are supported. The default fill of the Scene is Color.WHITE, but it is more commonly the case that the initial color shown to users is the background fill of the root node of the Scene, as it typically is stretched to take up all available space in the Scene. The root node of the Scene 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 interface HasFillProperty
      Default value:
      WHITE
      Returns:
      the fill property
      See Also:
    • getX

      public final double getX()
      Gets the value of the x property.
      Property description:
      The horizontal location of this Scene on the Window.
      Returns:
      the value of the x property
      See Also:
    • xProperty

      public final ReadOnlyDoubleProperty xProperty()
      The horizontal location of this Scene on the Window.
      Returns:
      the x property
      See Also:
    • getY

      public final double getY()
      Gets the value of the y property.
      Property description:
      The vertical location of this Scene on the Window.
      Returns:
      the value of the y property
      See Also:
    • yProperty

      public final ReadOnlyDoubleProperty yProperty()
      The vertical location of this Scene on the Window.
      Returns:
      the y property
      See Also:
    • rootProperty

      public Property<Parent> rootProperty()
      Specified by:
      rootProperty in interface HasRootProperty
      Returns:
      the root property
      See Also:
    • getWindow

      public final Window getWindow()
      Gets the value of the window property.
      Property description:
      The Window for this Scene
      Returns:
      the value of the window property
      See Also:
    • windowProperty

      public final ReadOnlyProperty<Window> windowProperty()
      The Window for this Scene
      Returns:
      the window property
      See Also:
    • impl_setWindow

      public void impl_setWindow(Window value)
    • resizeRootToPreferredSize

      public final void resizeRootToPreferredSize(Parent root)
    • getFocusOwner

      public final Node getFocusOwner()
      Gets the value of the focusOwner 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

      public final Property<Node> 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

      public ObservableMap<KeyCombination,Runnable> getAccelerators()
      Gets the list of accelerators for this Scene.
      Returns:
      the list of accelerators
    • setCursor

      public final void setCursor(Cursor value)
      Sets the value of the cursor property.
      Property description:
      Defines the mouse cursor for this Scene.
      Parameters:
      value - the value for the cursor property
      See Also:
    • getCursor

      public final Cursor getCursor()
      Gets the value of the cursor property.
      Property description:
      Defines the mouse cursor for this Scene.
      Returns:
      the value of the cursor property
      See Also:
    • cursorProperty

      public final ObjectProperty<Cursor> cursorProperty()
      Defines the mouse cursor for this Scene.
      Returns:
      the cursor property
      See Also:
    • setEventDispatcher

      public final void setEventDispatcher(EventDispatcher value)
      Sets the value of the eventDispatcher 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 the eventDispatcher property
      See Also:
    • getEventDispatcher

      public final EventDispatcher getEventDispatcher()
      Gets the value of the eventDispatcher 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

      public final ObjectProperty<EventDispatcher> eventDispatcherProperty()
      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 eventDispatcher property
      See Also:
    • buildEventDispatchChain

      public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)
      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 interface EventTarget
      Parameters:
      tail - the initial chain to build from
      Returns:
      the resulting event dispatch chain for this scene
    • getProperties

      public final ObservableMap<Object,Object> 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

      public void setUserData(Object value)
      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 calling getUserData().
      Parameters:
      value - The value to be stored - this can later be retrieved by calling getUserData().
      Since:
      JavaFX 8u40
    • getUserData

      public Object getUserData()
      Returns a previously set Object property, or null if no such property has been set using the setUserData(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

      public SceneRequester getSceneRequester()
    • updateChildrenPeers

      public void updateChildrenPeers(Collection<Node> nodes)
    • getOrCreateAndBindNodePeer

      public NodePeer getOrCreateAndBindNodePeer(Node node)
    • isPulseRunning

      public boolean isPulseRunning()
    • startPulse

      public void startPulse()
    • stopPulse

      public void stopPulse()
    • doLayoutPass

      protected void doLayoutPass()
    • getOrCreateDndGesture

      public Scene.DnDGesture getOrCreateDndGesture()
    • clearDndGesture

      public void clearDndGesture()
    • setOnMouseClicked

      public final void setOnMouseClicked(EventHandler<? super MouseEvent> value)
      Sets the value of the onMouseClicked 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 the onMouseClicked property
      See Also:
    • getOnMouseClicked

      public final EventHandler<? super MouseEvent> getOnMouseClicked()
      Gets the value of the onMouseClicked 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

      public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseClickedProperty()
      Defines a function to be called when a mouse button has been clicked (pressed and released) on this Scene.
      Returns:
      the onMouseClicked property
      See Also:
    • setOnMousePressed

      public final void setOnMousePressed(EventHandler<? super MouseEvent> value)
      Sets the value of the onMousePressed property.
      Property description:
      Defines a function to be called when a mouse button has been pressed on this Scene.
      Parameters:
      value - the value for the onMousePressed property
      See Also:
    • getOnMousePressed

      public final EventHandler<? super MouseEvent> getOnMousePressed()
      Gets the value of the onMousePressed 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

      public final ObjectProperty<EventHandler<? super MouseEvent>> onMousePressedProperty()
      Defines a function to be called when a mouse button has been pressed on this Scene.
      Returns:
      the onMousePressed property
      See Also:
    • setOnMouseReleased

      public final void setOnMouseReleased(EventHandler<? super MouseEvent> value)
      Sets the value of the onMouseReleased property.
      Property description:
      Defines a function to be called when a mouse button has been released on this Scene.
      Parameters:
      value - the value for the onMouseReleased property
      See Also:
    • getOnMouseReleased

      public final EventHandler<? super MouseEvent> getOnMouseReleased()
      Gets the value of the onMouseReleased 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

      public final ObjectProperty<EventHandler<? super MouseEvent>> onMouseReleasedProperty()
      Defines a function to be called when a mouse button has been released on this Scene.
      Returns:
      the onMouseReleased property
      See Also:
    • getStylesheets

      public final ObservableList<String> 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.

      
       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.
      Returns:
      the list of stylesheets to use with this scene
    • setOnKeyPressed

      public final void setOnKeyPressed(EventHandler<? super KeyEvent> value)
      Sets the value of the onKeyPressed property.
      Property description:
      Defines a function to be called when some Node of this Scene 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 the onKeyPressed property
      See Also:
    • getOnKeyPressed

      public final EventHandler<? super KeyEvent> getOnKeyPressed()
      Gets the value of the onKeyPressed property.
      Property description:
      Defines a function to be called when some Node of this Scene 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

      public final ObjectProperty<EventHandler<? super KeyEvent>> onKeyPressedProperty()
      Defines a function to be called when some Node of this Scene 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

      public final void setOnKeyReleased(EventHandler<? super KeyEvent> value)
      Sets the value of the onKeyReleased property.
      Property description:
      Defines a function to be called when some Node of this Scene 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 the onKeyReleased property
      See Also:
    • getOnKeyReleased

      public final EventHandler<? super KeyEvent> getOnKeyReleased()
      Gets the value of the onKeyReleased property.
      Property description:
      Defines a function to be called when some Node of this Scene 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

      public final ObjectProperty<EventHandler<? super KeyEvent>> onKeyReleasedProperty()
      Defines a function to be called when some Node of this Scene 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

      public final void setOnKeyTyped(EventHandler<? super KeyEvent> value)
      Sets the value of the onKeyTyped property.
      Property description:
      Defines a function to be called when some Node of this Scene 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 the onKeyTyped property
      See Also:
    • getOnKeyTyped

      public final EventHandler<? super KeyEvent> getOnKeyTyped()
      Gets the value of the onKeyTyped property.
      Property description:
      Defines a function to be called when some Node of this Scene 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

      public final ObjectProperty<EventHandler<? super KeyEvent>> onKeyTypedProperty()
      Defines a function to be called when some Node of this Scene 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 an Event 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 handler
      eventHandler - 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 unregister
      eventHandler - 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 an Event 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 filter
      eventFilter - 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 unregister
      eventFilter - 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 eventHandler
      eventHandler - 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.