public class Window extends Object implements EventTarget
A top level window within which a scene is hosted, and with which the user
interacts. A Window might be a Stage
, PopupWindow
, or other
such top level. A Window is used also for browser plug-in based deployments.
Type | Property and Description |
---|---|
ObjectProperty<EventDispatcher> |
eventDispatcher
Specifies the event dispatcher for this node.
|
ReadOnlyBooleanProperty |
focused
Whether or not this
Window has the keyboard or input focus. |
ReadOnlyDoubleProperty |
height
The height of this
Stage . |
ObjectProperty<EventHandler<WindowEvent>> |
onCloseRequest
Called when there is an external request to close this
Window . |
ObjectProperty<EventHandler<WindowEvent>> |
onHidden
Called just after the Window has been hidden.
|
ObjectProperty<EventHandler<WindowEvent>> |
onHiding
Called just prior to the Window being hidden.
|
ObjectProperty<EventHandler<WindowEvent>> |
onShowing
Called just prior to the Window being shown.
|
ObjectProperty<EventHandler<WindowEvent>> |
onShown
Called just after the Window is shown.
|
DoubleProperty |
opacity
Defines the opacity of the
Stage as a value between 0.0 and 1.0. |
ReadOnlyObjectProperty<Scene> |
scene
The
Scene to be rendered on this Stage . |
ReadOnlyBooleanProperty |
showing
Whether or not this
Stage is showing (that is, open on the
user's system). |
ReadOnlyDoubleProperty |
width
The width of this
Stage . |
ReadOnlyDoubleProperty |
x
The horizontal location of this
Stage on the screen. |
ReadOnlyDoubleProperty |
y
The vertical location of this
Stage on the screen. |
Modifier | Constructor and Description |
---|---|
protected |
Window() |
Modifier and Type | Method and Description |
---|---|
<T extends Event> |
addEventFilter(EventType<T> eventType,
EventHandler<? super T> eventFilter)
Registers an event filter to this node.
|
<T extends Event> |
addEventHandler(EventType<T> eventType,
EventHandler<? super T> eventHandler)
Registers an event handler to this node.
|
EventDispatchChain |
buildEventDispatchChain(EventDispatchChain tail)
Construct an event dispatch chain for this window.
|
void |
centerOnScreen()
Sets x and y properties on this Window so that it is centered on the
curent screen.
|
ObjectProperty<EventDispatcher> |
eventDispatcherProperty()
Specifies the event dispatcher for this node.
|
void |
fireEvent(Event event)
Fires the specified event.
|
ReadOnlyBooleanProperty |
focusedProperty()
Whether or not this
Window has the keyboard or input focus. |
EventDispatcher |
getEventDispatcher()
Gets the value of the property eventDispatcher.
|
double |
getHeight()
Gets the value of the property height.
|
EventHandler<WindowEvent> |
getOnCloseRequest()
Gets the value of the property onCloseRequest.
|
EventHandler<WindowEvent> |
getOnHidden()
Gets the value of the property onHidden.
|
EventHandler<WindowEvent> |
getOnHiding()
Gets the value of the property onHiding.
|
EventHandler<WindowEvent> |
getOnShowing()
Gets the value of the property onShowing.
|
EventHandler<WindowEvent> |
getOnShown()
Gets the value of the property onShown.
|
double |
getOpacity()
Gets the value of the property opacity.
|
ObservableMap<Object,Object> |
getProperties()
Returns an observable map of properties on this node for use primarily
by application developers.
|
Scene |
getScene()
Gets the value of the property scene.
|
Object |
getUserData()
Returns a previously set Object property, or null if no such property
has been set using the
setUserData(java.lang.Object) method. |
double |
getWidth()
Gets the value of the property width.
|
double |
getX()
Gets the value of the property x.
|
double |
getY()
Gets the value of the property y.
|
boolean |
hasProperties()
Tests if Window has properties.
|
ReadOnlyDoubleProperty |
heightProperty()
The height of this
Stage . |
void |
hide()
Attempts to hide this Window by setting the visibility to false.
|
boolean |
isFocused()
Gets the value of the property focused.
|
boolean |
isShowing()
Gets the value of the property showing.
|
ObjectProperty<EventHandler<WindowEvent>> |
onCloseRequestProperty()
Called when there is an external request to close this
Window . |
ObjectProperty<EventHandler<WindowEvent>> |
onHiddenProperty()
Called just after the Window has been hidden.
|
ObjectProperty<EventHandler<WindowEvent>> |
onHidingProperty()
Called just prior to the Window being hidden.
|
ObjectProperty<EventHandler<WindowEvent>> |
onShowingProperty()
Called just prior to the Window being shown.
|
ObjectProperty<EventHandler<WindowEvent>> |
onShownProperty()
Called just after the Window is shown.
|
DoubleProperty |
opacityProperty()
Defines the opacity of the
Stage as a value between 0.0 and 1.0. |
<T extends Event> |
removeEventFilter(EventType<T> eventType,
EventHandler<? super T> eventFilter)
Unregisters a previously registered event filter from this node.
|
<T extends Event> |
removeEventHandler(EventType<T> eventType,
EventHandler<? super T> eventHandler)
Unregisters a previously registered event handler from this node.
|
void |
requestFocus()
Requests that this
Window get the input focus. |
ReadOnlyObjectProperty<Scene> |
sceneProperty()
The
Scene to be rendered on this Stage . |
void |
setEventDispatcher(EventDispatcher value)
Sets the value of the property eventDispatcher.
|
protected <T extends Event> |
setEventHandler(EventType<T> eventType,
EventHandler<? super T> eventHandler)
Sets the handler to use for this event type.
|
void |
setHeight(double value)
Sets the value of the property height.
|
void |
setOnCloseRequest(EventHandler<WindowEvent> value)
Sets the value of the property onCloseRequest.
|
void |
setOnHidden(EventHandler<WindowEvent> value)
Sets the value of the property onHidden.
|
void |
setOnHiding(EventHandler<WindowEvent> value)
Sets the value of the property onHiding.
|
void |
setOnShowing(EventHandler<WindowEvent> value)
Sets the value of the property onShowing.
|
void |
setOnShown(EventHandler<WindowEvent> value)
Sets the value of the property onShown.
|
void |
setOpacity(double value)
Sets the value of the property opacity.
|
protected void |
setScene(Scene value)
Sets the value of the property scene.
|
void |
setUserData(Object value)
Convenience method for setting a single Object property that can be
retrieved at a later date.
|
void |
setWidth(double value)
Sets the value of the property width.
|
void |
setX(double value)
Sets the value of the property x.
|
void |
setY(double value)
Sets the value of the property y.
|
protected void |
show()
Attempts to show this Window by setting visibility to true
|
ReadOnlyBooleanProperty |
showingProperty()
Whether or not this
Stage is showing (that is, open on the
user's system). |
void |
sizeToScene()
Set the width and height of this Window to match the size of the content
of this Window's Scene.
|
ReadOnlyDoubleProperty |
widthProperty()
The width of this
Stage . |
ReadOnlyDoubleProperty |
xProperty()
The horizontal location of this
Stage on the screen. |
ReadOnlyDoubleProperty |
yProperty()
The vertical location of this
Stage on the screen. |
public final ReadOnlyDoubleProperty xProperty
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.getX()
,
setX(double)
public final ReadOnlyDoubleProperty yProperty
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.getY()
,
setY(double)
public final ReadOnlyDoubleProperty widthProperty
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.
getWidth()
,
setWidth(double)
public final ReadOnlyDoubleProperty heightProperty
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.
getHeight()
,
setHeight(double)
public final ReadOnlyBooleanProperty focusedProperty
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.
isFocused()
,
setFocused(boolean)
public final ReadOnlyObjectProperty<Scene> sceneProperty
Scene
to be rendered on this Stage
. There can only
be one Scene
on the Stage
at a time, and a Scene
can only be on one Stage
at a time. Setting a Scene
on
a different Stage
will cause the old Stage
to lose the
reference before the new one gains it. You may swap Scene
s on
a Stage
at any time, even while in full-screen exclusive mode.
An IllegalStateException
is thrown if this property is set
on a thread other than the JavaFX Application Thread.getScene()
,
setScene(Scene)
public final DoubleProperty opacityProperty
Stage
as a value between 0.0 and 1.0.
The opacity is reflected across the Stage
, its Decoration
and its Scene
content. On a JavaFX runtime platform that does not
support opacity, assigning a value to this variable will have no
visible difference. A Stage
with 0% opacity is fully translucent.
Typically, a Stage
with 0% opacity will not receive any mouse
events.getOpacity()
,
setOpacity(double)
public final ObjectProperty<EventHandler<WindowEvent>> onCloseRequestProperty
Window
.
The installed event handler can prevent window closing by consuming the
received event.public final ObjectProperty<EventHandler<WindowEvent>> onShowingProperty
getOnShowing()
,
setOnShowing(EventHandler)
public final ObjectProperty<EventHandler<WindowEvent>> onShownProperty
getOnShown()
,
setOnShown(EventHandler)
public final ObjectProperty<EventHandler<WindowEvent>> onHidingProperty
getOnHiding()
,
setOnHiding(EventHandler)
public final ObjectProperty<EventHandler<WindowEvent>> onHiddenProperty
Window
is hidden, this event handler is invoked allowing
the developer to clean up resources or perform other tasks when the
Window
is closed.getOnHidden()
,
setOnHidden(EventHandler)
public final ReadOnlyBooleanProperty showingProperty
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.isShowing()
public final ObjectProperty<EventDispatcher> eventDispatcherProperty
EventDispatcher
,
the new dispatcher should forward events to the replaced dispatcher
to maintain the node's default event handling behavior.public void sizeToScene()
public void centerOnScreen()
public final void setX(double value)
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.public final double getX()
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.public final ReadOnlyDoubleProperty xProperty()
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.getX()
,
setX(double)
public final void setY(double value)
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.public final double getY()
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.public final ReadOnlyDoubleProperty yProperty()
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.getY()
,
setY(double)
public final void setWidth(double value)
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.
public final double getWidth()
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.
public final ReadOnlyDoubleProperty widthProperty()
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.
getWidth()
,
setWidth(double)
public final void setHeight(double value)
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.
public final double getHeight()
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.
public final ReadOnlyDoubleProperty heightProperty()
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.
getHeight()
,
setHeight(double)
public final void requestFocus()
Window
get the input focus.public final boolean isFocused()
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.
public final ReadOnlyBooleanProperty focusedProperty()
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.
isFocused()
,
setFocused(boolean)
public final ObservableMap<Object,Object> getProperties()
public boolean hasProperties()
public void setUserData(Object value)
getUserData()
.value
- The value to be stored - this can later be retrieved by calling
getUserData()
.public Object getUserData()
setUserData(java.lang.Object)
method.protected void setScene(Scene value)
Scene
to be rendered on this Stage
. There can only
be one Scene
on the Stage
at a time, and a Scene
can only be on one Stage
at a time. Setting a Scene
on
a different Stage
will cause the old Stage
to lose the
reference before the new one gains it. You may swap Scene
s on
a Stage
at any time, even while in full-screen exclusive mode.
An IllegalStateException
is thrown if this property is set
on a thread other than the JavaFX Application Thread.public final Scene getScene()
Scene
to be rendered on this Stage
. There can only
be one Scene
on the Stage
at a time, and a Scene
can only be on one Stage
at a time. Setting a Scene
on
a different Stage
will cause the old Stage
to lose the
reference before the new one gains it. You may swap Scene
s on
a Stage
at any time, even while in full-screen exclusive mode.
An IllegalStateException
is thrown if this property is set
on a thread other than the JavaFX Application Thread.public final ReadOnlyObjectProperty<Scene> sceneProperty()
Scene
to be rendered on this Stage
. There can only
be one Scene
on the Stage
at a time, and a Scene
can only be on one Stage
at a time. Setting a Scene
on
a different Stage
will cause the old Stage
to lose the
reference before the new one gains it. You may swap Scene
s on
a Stage
at any time, even while in full-screen exclusive mode.
An IllegalStateException
is thrown if this property is set
on a thread other than the JavaFX Application Thread.getScene()
,
setScene(Scene)
public final void setOpacity(double value)
Stage
as a value between 0.0 and 1.0.
The opacity is reflected across the Stage
, its Decoration
and its Scene
content. On a JavaFX runtime platform that does not
support opacity, assigning a value to this variable will have no
visible difference. A Stage
with 0% opacity is fully translucent.
Typically, a Stage
with 0% opacity will not receive any mouse
events.public final double getOpacity()
Stage
as a value between 0.0 and 1.0.
The opacity is reflected across the Stage
, its Decoration
and its Scene
content. On a JavaFX runtime platform that does not
support opacity, assigning a value to this variable will have no
visible difference. A Stage
with 0% opacity is fully translucent.
Typically, a Stage
with 0% opacity will not receive any mouse
events.public final DoubleProperty opacityProperty()
Stage
as a value between 0.0 and 1.0.
The opacity is reflected across the Stage
, its Decoration
and its Scene
content. On a JavaFX runtime platform that does not
support opacity, assigning a value to this variable will have no
visible difference. A Stage
with 0% opacity is fully translucent.
Typically, a Stage
with 0% opacity will not receive any mouse
events.getOpacity()
,
setOpacity(double)
public final void setOnCloseRequest(EventHandler<WindowEvent> value)
Window
.
The installed event handler can prevent window closing by consuming the
received event.public final EventHandler<WindowEvent> getOnCloseRequest()
Window
.
The installed event handler can prevent window closing by consuming the
received event.public final ObjectProperty<EventHandler<WindowEvent>> onCloseRequestProperty()
Window
.
The installed event handler can prevent window closing by consuming the
received event.public final void setOnShowing(EventHandler<WindowEvent> value)
public final EventHandler<WindowEvent> getOnShowing()
public final ObjectProperty<EventHandler<WindowEvent>> onShowingProperty()
getOnShowing()
,
setOnShowing(EventHandler)
public final void setOnShown(EventHandler<WindowEvent> value)
public final EventHandler<WindowEvent> getOnShown()
public final ObjectProperty<EventHandler<WindowEvent>> onShownProperty()
getOnShown()
,
setOnShown(EventHandler)
public final void setOnHiding(EventHandler<WindowEvent> value)
public final EventHandler<WindowEvent> getOnHiding()
public final ObjectProperty<EventHandler<WindowEvent>> onHidingProperty()
getOnHiding()
,
setOnHiding(EventHandler)
public final void setOnHidden(EventHandler<WindowEvent> value)
Window
is hidden, this event handler is invoked allowing
the developer to clean up resources or perform other tasks when the
Window
is closed.public final EventHandler<WindowEvent> getOnHidden()
Window
is hidden, this event handler is invoked allowing
the developer to clean up resources or perform other tasks when the
Window
is closed.public final ObjectProperty<EventHandler<WindowEvent>> onHiddenProperty()
Window
is hidden, this event handler is invoked allowing
the developer to clean up resources or perform other tasks when the
Window
is closed.getOnHidden()
,
setOnHidden(EventHandler)
public final boolean isShowing()
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.public final ReadOnlyBooleanProperty showingProperty()
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.isShowing()
protected void show()
IllegalStateException
- if this method is called on a thread
other than the JavaFX Application Thread.public void hide()
IllegalStateException
- if this method is called on a thread
other than the JavaFX Application Thread.public final void setEventDispatcher(EventDispatcher value)
EventDispatcher
,
the new dispatcher should forward events to the replaced dispatcher
to maintain the node's default event handling behavior.public final EventDispatcher getEventDispatcher()
EventDispatcher
,
the new dispatcher should forward events to the replaced dispatcher
to maintain the node's default event handling behavior.public final ObjectProperty<EventDispatcher> eventDispatcherProperty()
EventDispatcher
,
the new dispatcher should forward events to the replaced dispatcher
to maintain the node's default event handling behavior.public final <T extends Event> void addEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
Event
of the specified type during the bubbling
phase of event delivery.T
- the specific event class of the handlereventType
- the type of the events to receive by the handlereventHandler
- the handler to registerNullPointerException
- if the event type or handler is nullpublic final <T extends Event> void removeEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
T
- the specific event class of the handlereventType
- the event type from which to unregistereventHandler
- the handler to unregisterNullPointerException
- if the event type or handler is nullpublic final <T extends Event> void addEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)
Event
of the specified type during the capturing
phase of event delivery.T
- the specific event class of the filtereventType
- the type of the events to receive by the filtereventFilter
- the filter to registerNullPointerException
- if the event type or filter is nullpublic final <T extends Event> void removeEventFilter(EventType<T> eventType, EventHandler<? super T> eventFilter)
T
- the specific event class of the filtereventType
- the event type from which to unregistereventFilter
- the filter to unregisterNullPointerException
- if the event type or filter is nullprotected final <T extends Event> void setEventHandler(EventType<T> eventType, EventHandler<? super T> eventHandler)
T
- the specific event class of the handlereventType
- the event type to associate with the given eventHandlereventHandler
- the handler to register, or null to unregisterNullPointerException
- if the event type is nullpublic final void fireEvent(Event event)
This method must be called on the FX user thread.
event
- the event to firepublic EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)
buildEventDispatchChain
in interface EventTarget
tail
- the initial chain to build fromCopyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.