Package javafx.stage

Class Window

java.lang.Object
javafx.stage.Window
All Implemented Interfaces:
HasHeightProperty, HasSceneProperty, HasWidthProperty, EventTarget
Direct Known Subclasses:
PopupWindow, Stage

public class Window extends Object implements EventTarget, HasSceneProperty, HasWidthProperty, HasHeightProperty
Author:
Bruno Salmon
  • Property Details

    • scene

      public Property<Scene> sceneProperty
      Specified by:
      sceneProperty in interface HasSceneProperty
      Returns:
      the scene property
      See Also:
    • width

      public final DoubleProperty widthProperty
      The width of this Stage. Changing this attribute will narrow or widen the width of the Stage. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false. This value includes any and all decorations which may be added by the Operating System such as resizable frame handles. Typical applications will set the Scene width instead.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Specified by:
      widthProperty in interface HasWidthProperty
      Returns:
      the width property
      See Also:
    • height

      public final DoubleProperty heightProperty
      The height of this Stage. Changing this attribute will shrink or heighten the height of the Stage. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false. This value includes any and all decorations which may be added by the Operating System such as the title bar. Typical applications will set the Scene height instead.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Specified by:
      heightProperty in interface HasHeightProperty
      Returns:
      the height property
      See Also:
    • x

      public final ReadOnlyDoubleProperty xProperty
      The horizontal location of this Stage on the screen. Changing this attribute will move the Stage horizontally. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      See Also:
    • y

      public final ReadOnlyDoubleProperty yProperty
      The vertical location of this Stage on the screen. Changing this attribute will move the Stage vertically. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      See Also:
    • showing

      public final ReadOnlyProperty<Boolean> showingProperty
      Whether or not this Stage is showing (that is, open on the user's system). The Stage might be "showing", yet the user might not be able to see it due to the Stage being rendered behind another window or due to the Stage being positioned off the monitor.
      Default value:
      false
      See Also:
    • focused

      public final ReadOnlyProperty<Boolean> focusedProperty
      Whether or not this Window has the keyboard or input focus.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      See Also:
    • onCloseRequest

      public final ObjectProperty<EventHandler<WindowEvent>> onCloseRequestProperty
      Called when there is an external request to close this Window. The installed event handler can prevent window closing by consuming the received event.
      See Also:
    • eventDispatcher

      public final ObjectProperty<EventDispatcher> eventDispatcherProperty
      Specifies the event dispatcher for this node. The default event dispatcher sends the received events to the registered event handlers and filters. When replacing the value with a new EventDispatcher, the new dispatcher should forward events to the replaced dispatcher to maintain the node's default event handling behavior.
      See Also:
  • Field Details

    • peerListener

      protected WindowPeerListener peerListener
      The listener that gets called by peer. It's also responsible for window size/location synchronization with the window peer, which occurs on every pulse.
    • impl_peer

      protected volatile WindowPeer impl_peer
      The peer of this Stage. All external access should be made though getPeer(). Implementors note: Please ensure that this variable is defined *after* style and *before* the other variables so that style has been initialized prior to this call, and so that impl_peer is initialized prior to subsequent initialization.
  • Constructor Details

    • Window

      public Window()
  • Method Details

    • impl_getPeer

      public WindowPeer impl_getPeer()
      Get Stage's peer
    • createPeer

      protected WindowPeer createPeer()
    • sceneProperty

      public Property<Scene> sceneProperty()
      Specified by:
      sceneProperty in interface HasSceneProperty
      Returns:
      the scene property
      See Also:
    • setWidth

      public final void setWidth(double value)
      Sets the value of the width property.
      Property description:
      The width of this Stage. Changing this attribute will narrow or widen the width of the Stage. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false. This value includes any and all decorations which may be added by the Operating System such as resizable frame handles. Typical applications will set the Scene width instead.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Parameters:
      value - the value for the width property
      See Also:
    • widthProperty

      public final DoubleProperty widthProperty()
      The width of this Stage. Changing this attribute will narrow or widen the width of the Stage. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false. This value includes any and all decorations which may be added by the Operating System such as resizable frame handles. Typical applications will set the Scene width instead.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Specified by:
      widthProperty in interface HasWidthProperty
      Returns:
      the width property
      See Also:
    • setHeight

      public final void setHeight(double value)
      Sets the value of the height property.
      Property description:
      The height of this Stage. Changing this attribute will shrink or heighten the height of the Stage. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false. This value includes any and all decorations which may be added by the Operating System such as the title bar. Typical applications will set the Scene height instead.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Parameters:
      value - the value for the height property
      See Also:
    • heightProperty

      public final DoubleProperty heightProperty()
      The height of this Stage. Changing this attribute will shrink or heighten the height of the Stage. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false. This value includes any and all decorations which may be added by the Operating System such as the title bar. Typical applications will set the Scene height instead.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Specified by:
      heightProperty in interface HasHeightProperty
      Returns:
      the height property
      See Also:
    • notifySizeChanged

      public void notifySizeChanged(double newWidth, double newHeight)
      Notification from the windowing system that the window's size has changed.
      Parameters:
      newWidth - the new window width
      newHeight - the new window height
    • setX

      public final void setX(double value)
      Sets the value of the x property.
      Property description:
      The horizontal location of this Stage on the screen. Changing this attribute will move the Stage horizontally. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      Parameters:
      value - the value for the x property
      See Also:
    • getX

      public final double getX()
      Gets the value of the x property.
      Property description:
      The horizontal location of this Stage on the screen. Changing this attribute will move the Stage horizontally. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      Returns:
      the value of the x property
      See Also:
    • xProperty

      public final ReadOnlyDoubleProperty xProperty()
      The horizontal location of this Stage on the screen. Changing this attribute will move the Stage horizontally. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      Returns:
      the x property
      See Also:
    • setY

      public final void setY(double value)
      Sets the value of the y property.
      Property description:
      The vertical location of this Stage on the screen. Changing this attribute will move the Stage vertically. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      Parameters:
      value - the value for the y property
      See Also:
    • getY

      public final double getY()
      Gets the value of the y property.
      Property description:
      The vertical location of this Stage on the screen. Changing this attribute will move the Stage vertically. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      Returns:
      the value of the y property
      See Also:
    • yProperty

      public final ReadOnlyDoubleProperty yProperty()
      The vertical location of this Stage on the screen. Changing this attribute will move the Stage vertically. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
      Returns:
      the y property
      See Also:
    • isShowing

      public final boolean isShowing()
    • showingProperty

      public final ReadOnlyProperty<Boolean> showingProperty()
      Whether or not this Stage is showing (that is, open on the user's system). The Stage might be "showing", yet the user might not be able to see it due to the Stage being rendered behind another window or due to the Stage being positioned off the monitor.
      Default value:
      false
      Returns:
      the showing property
    • show

      protected void show()
      Attempts to show this Window by setting visibility to true
      Throws:
      IllegalStateException - if this method is called on a thread other than the JavaFX Application Thread.
    • hide

      public void hide()
      Attempts to hide this Window by setting the visibility to false.
      Throws:
      IllegalStateException - if this method is called on a thread other than the JavaFX Application Thread.
    • impl_visibleChanged

      protected void impl_visibleChanged(boolean visible)
      This can be replaced by listening for the onShown/onHidden events
    • requestFocus

      public final void requestFocus()
      Requests that this Window get the input focus.
    • isFocused

      public final boolean isFocused()
    • focusedProperty

      public final ReadOnlyProperty<Boolean> focusedProperty()
      Whether or not this Window has the keyboard or input focus.

      The property is read only because it can be changed externally by the underlying platform and therefore must not be bindable.

      Returns:
      the focused property
      See Also:
      • setFocused(boolean)
    • sizeToScene

      public void sizeToScene()
      Set the width and height of this Window to match the size of the content of this Window's Scene.
    • centerOnScreen

      public void centerOnScreen()
      Sets x and y properties on this Window so that it is centered on the curent screen. The current screen is determined from the intersection of current window bounds and visual bounds of all screens.
    • setOnCloseRequest

      public final void setOnCloseRequest(EventHandler<WindowEvent> value)
      Sets the value of the onCloseRequest property.
      Property description:
      Called when there is an external request to close this Window. The installed event handler can prevent window closing by consuming the received event.
      Parameters:
      value - the value for the onCloseRequest property
      See Also:
    • getOnCloseRequest

      public final EventHandler<WindowEvent> getOnCloseRequest()
      Gets the value of the onCloseRequest property.
      Property description:
      Called when there is an external request to close this Window. The installed event handler can prevent window closing by consuming the received event.
      Returns:
      the value of the onCloseRequest property
      See Also:
    • onCloseRequestProperty

      public final ObjectProperty<EventHandler<WindowEvent>> onCloseRequestProperty()
      Called when there is an external request to close this Window. The installed event handler can prevent window closing by consuming the received event.
      Returns:
      the onCloseRequest 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 node. The default event dispatcher sends the received events to the registered event handlers and filters. When replacing the value with a new EventDispatcher, the new dispatcher should forward events to the replaced dispatcher to maintain the node'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 node. The default event dispatcher sends the received events to the registered event handlers and filters. When replacing the value with a new EventDispatcher, the new dispatcher should forward events to the replaced dispatcher to maintain the node'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 node. The default event dispatcher sends the received events to the registered event handlers and filters. When replacing the value with a new EventDispatcher, the new dispatcher should forward events to the replaced dispatcher to maintain the node's default event handling behavior.
      Returns:
      the eventDispatcher property
      See Also:
    • addEventHandler

      public final <T extends Event> void addEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
      Registers an event handler to this node. The handler is called when the node 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 node. 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 node. The filter is called when the node 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 node. 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
    • fireEvent

      public final void fireEvent(Event event)
      Fires the specified event.

      This method must be called on the FX user thread.

      Parameters:
      event - the event to fire
    • buildEventDispatchChain

      public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)
      Construct an event dispatch chain for this window.
      Specified by:
      buildEventDispatchChain in interface EventTarget
      Parameters:
      tail - the initial chain to build from
      Returns:
      the resulting event dispatch chain for this window