Class Stage
- All Implemented Interfaces:
HasHeightProperty
,HasSceneProperty
,HasTitleProperty
,HasWidthProperty
,EventTarget
Stage
class is the top level JavaFX container.
The primary Stage is constructed by the platform. Additional Stage
objects may be constructed by the application.
Stage objects must be constructed and modified on the JavaFX Application Thread.
Many of the Stage
properties are read only because they can
be changed externally by the underlying platform and therefore must
not be bindable.
Style
A stage has one of the following styles:
StageStyle.DECORATED
- a stage with a solid white background and platform decorations.StageStyle.UNDECORATED
- a stage with a solid white background and no decorations.StageStyle.TRANSPARENT
- a stage with a transparent background and no decorations.StageStyle.UTILITY
- a stage with a solid white background and minimal platform decorations.
The style must be initialized before the stage is made visible.
On some platforms decorations might not be available. For example, on some mobile or embedded devices. In these cases a request for a DECORATED or UTILITY window will be accepted, but no decorations will be shown.
Owner
A stage can optionally have an owner Window. When a window is a stage's owner, it is said to be the parent of that stage.
Owned Stages are tied to the parent Window. An owned stage will always be on top of its parent window. When a parent window is closed or iconified, then all owned windows will be affected as well. Owned Stages cannot be independantly iconified.
The owner must be initialized before the stage is made visible.
Modality
A stage has one of the following modalities:
Modality.NONE
- a stage that does not block any other window.Modality.WINDOW_MODAL
- a stage that blocks input events from being delivered to all windows from its owner (parent) to its root. Its root is the closest ancestor window without an owner.Modality.APPLICATION_MODAL
- a stage that blocks input events from being delivered to all windows from the same application, except for those from its child hierarchy.
When a window is blocked by a modal stage its Z-order relative to its ancestors
is preserved, and it receives no input events and no window activation events,
but continues to animate and render normally.
Note that showing a modal stage does not necessarily block the caller. The
show()
method returns immediately regardless of the modality of the stage.
Use the showAndWait()
method if you need to block the caller until
the modal stage is hidden (closed).
The modality must be initialized before the stage is made visible.
Example:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class HelloWorld extends Application {
@Override public void start(Stage stage) {
Text text = new Text(10, 40, "Hello World!");
text.setFont(new Font(40));
Scene scene = new Scene(new Group(text));
stage.setTitle("Welcome to JavaFX!");
stage.setScene(scene);
stage.sizeToScene();
stage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
produces the following on Windows:
produces the following on Mac OSX:
produces the following on Linux:
- Since:
- JavaFX 2.0
-
Property Summary
PropertiesTypePropertyDescriptionfinal ReadOnlyBooleanProperty
Defines whether theStage
is resizable or not by the user.Properties inherited from class javafx.stage.Window
eventDispatcher, focused, height, onCloseRequest, scene, showing, width, x, y
-
Field Summary
Fields inherited from class javafx.stage.Window
impl_peer, peerListener
-
Constructor Summary
ConstructorsConstructorDescriptionStage()
Creates a new instance of decoratedStage
.Stage
(StageStyle style) Creates a new instance ofStage
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes thisStage
.protected StagePeer
final ReadOnlyBooleanProperty
final ObservableList<Image>
getIcons()
final Modality
Retrieves the modality attribute for this stage.final Window
getOwner()
Retrieves the owner Window for this stage, or null for an unowned stage.final StageStyle
getStyle()
Retrieves the style attribute for this stage.final void
initModality
(Modality modality) Specifies the modality for this stage.final void
Specifies the owner Window for this stage, or null for a top-level, unowned stage.final void
initStyle
(StageStyle style) Specifies the style for this stage.final boolean
Gets the value of thefullScreen
property.final boolean
Defines whether theStage
is resizable or not by the user.final void
setFullScreen
(boolean value) Sets the value of thefullScreen
property.void
setFullScreenExitHint
(String hint) void
setMinHeight
(double minHeight) void
setMinWidth
(double minWidth) final void
setResizable
(boolean value) Sets the value of theresizable
property.final void
Specify the scene to be used on this stage.final void
show()
Attempts to show this Window by setting visibility to truevoid
Shows this stage and waits for it to be hidden (closed) before returning to the caller.Methods inherited from class javafx.stage.Window
addEventFilter, addEventHandler, buildEventDispatchChain, centerOnScreen, eventDispatcherProperty, fireEvent, focusedProperty, getEventDispatcher, getOnCloseRequest, getX, getY, heightProperty, hide, impl_getPeer, impl_visibleChanged, isFocused, isShowing, notifySizeChanged, onCloseRequestProperty, removeEventFilter, removeEventHandler, requestFocus, sceneProperty, setEventDispatcher, setEventHandler, setHeight, setOnCloseRequest, setWidth, setX, setY, showingProperty, sizeToScene, widthProperty, xProperty, yProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasHeightProperty
getHeight, setHeight
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasSceneProperty
getScene
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasTitleProperty
getTitle, setTitle
Methods inherited from interface dev.webfx.kit.mapper.peers.javafxgraphics.markers.HasWidthProperty
getWidth, setWidth
-
Property Details
-
title
- Specified by:
titleProperty
in interfaceHasTitleProperty
- Returns:
- the
title
property - See Also:
-
resizable
Defines whether theStage
is resizable or not by the user. Programatically you may still change the size of the Stage. This is a hint which allows the implementation to optionally make the Stage resizable by the user.Warning: Since 8.0 the property cannot be bound and will throw
RuntimeException
on an attempt to do so. This is because the setting of resizable is asynchronous on some systems or generally might be set by the system / window manager.
Bidirectional binds are still allowed, as they don't block setting of the property by the system.- Default value:
- true
- See Also:
-
fullScreen
-
-
Constructor Details
-
Stage
public Stage()Creates a new instance of decoratedStage
.- Throws:
IllegalStateException
- if this constructor is called on a thread other than the JavaFX Application Thread.
-
Stage
Creates a new instance ofStage
.- Parameters:
style
- The style of theStage
- Throws:
IllegalStateException
- if this constructor is called on a thread other than the JavaFX Application Thread.
-
-
Method Details
-
createPeer
- Overrides:
createPeer
in classWindow
-
titleProperty
- Specified by:
titleProperty
in interfaceHasTitleProperty
- Returns:
- the
title
property - See Also:
-
setScene
Specify the scene to be used on this stage.- Specified by:
setScene
in interfaceHasSceneProperty
- Parameters:
value
- the value for thescene
property- See Also:
-
show
public final void show()Description copied from class:Window
Attempts to show this Window by setting visibility to true -
showAndWait
public void showAndWait()Shows this stage and waits for it to be hidden (closed) before returning to the caller. This method temporarily blocks processing of the current event, and starts a nested event loop to handle other events. This method must be called on the FX Application thread.A Stage is hidden (closed) by one of the following means:
- the application calls the
Window.hide()
orclose()
method on this stage - this stage has a non-null owner window, and its owner is closed
- the user closes the window via the window system (for example, by pressing the close button in the window decoration)
After the Stage is hidden, and the application has returned from the event handler to the event loop, the nested event loop terminates and this method returns to the caller.
For example, consider the following sequence of operations for different event handlers, assumed to execute in the order shown below:
void evtHander1(...) { stage1.showAndWait(); doSomethingAfterStage1Closed(...) } void evtHander2(...) { stage1.hide(); doSomethingElseHere(...) }
evtHandler1 will block at the call to showAndWait. It will resume execution after stage1 is hidden and the current event handler, in this case evtHandler2, returns to the event loop. This means that doSomethingElseHere will execute before doSomethingAfterStage1Closed.More than one stage may be shown with showAndWait. Each call will start a new nested event loop. The stages may be hidden in any order, but a particular nested event loop (and thus the showAndWait method for the associated stage) will only terminate after all inner event loops have also terminated.
For example, consider the following sequence of operations for different event handlers, assumed to execute in the order shown below:
void evtHander1() { stage1.showAndWait(); doSomethingAfterStage1Closed(...) } void evtHander2() { stage2.showAndWait(); doSomethingAfterStage2Closed(...) } void evtHander3() { stage1.hide(); doSomethingElseHere(...) } void evtHander4() { stage2.hide(); doSomethingElseHereToo(...) }
evtHandler1 will block at the call to stage1.showAndWait, starting up a nested event loop just like in the previous example. evtHandler2 will then block at the call to stage2.showAndWait, starting up another (inner) nested event loop. The first call to stage1.showAndWait will resume execution after stage1 is hidden, but only after the inner nested event loop started by stage2.showAndWait has terminated. This means that the call to stage1.showAndWait won't return until after evtHandler2 has returned. The order of execution is: stage1.showAndWait, stage2.showAndWait, stage1.hide, doSomethingElseHere, stage2.hide, doSomethingElseHereToo, doSomethingAfterStage2Closed, doSomethingAfterStage1Closed.This method must not be called on the primary stage or on a stage that is already visible. Additionally, it must either be called from an input event handler or from the run method of a Runnable passed to
Platform.runLater
. It must not be called during animation or layout processing.- Throws:
IllegalStateException
- if this method is called on a thread other than the JavaFX Application Thread.IllegalStateException
- if this method is called during animation or layout processing.IllegalStateException
- if this method is called on the primary stage.IllegalStateException
- if this stage is already showing.- Since:
- JavaFX 2.2
- the application calls the
-
initStyle
Specifies the style for this stage. This must be done prior to making the stage visible. The style is one of: StageStyle.DECORATED, StageStyle.UNDECORATED, StageStyle.TRANSPARENT, or StageStyle.UTILITY.- Default value:
- StageStyle.DECORATED
- Parameters:
style
- the style for this stage.- Throws:
IllegalStateException
- if this property is set after the stage has ever been made visible.
-
getStyle
Retrieves the style attribute for this stage.- Returns:
- the stage style.
-
initModality
Specifies the modality for this stage. This must be done prior to making the stage visible. The modality is one of: Modality.NONE, Modality.WINDOW_MODAL, or Modality.APPLICATION_MODAL.- Default value:
- Modality.NONE
- Parameters:
modality
- the modality for this stage.- Throws:
IllegalStateException
- if this property is set after the stage has ever been made visible.IllegalStateException
- if this stage is the primary stage.
-
getModality
Retrieves the modality attribute for this stage.- Returns:
- the modality.
-
initOwner
Specifies the owner Window for this stage, or null for a top-level, unowned stage. This must be done prior to making the stage visible.- Default value:
- null
- Parameters:
owner
- the owner for this stage.- Throws:
IllegalStateException
- if this property is set after the stage has ever been made visible.IllegalStateException
- if this stage is the primary stage.
-
getOwner
Retrieves the owner Window for this stage, or null for an unowned stage.- Returns:
- the owner Window.
-
setResizable
public final void setResizable(boolean value) Sets the value of theresizable
property.- Property description:
- Defines whether the
Stage
is resizable or not by the user. Programatically you may still change the size of the Stage. This is a hint which allows the implementation to optionally make the Stage resizable by the user.Warning: Since 8.0 the property cannot be bound and will throw
RuntimeException
on an attempt to do so. This is because the setting of resizable is asynchronous on some systems or generally might be set by the system / window manager.
Bidirectional binds are still allowed, as they don't block setting of the property by the system. - Default value:
- true
- Parameters:
value
- the value for theresizable
property- See Also:
-
isResizable
public final boolean isResizable() -
resizableProperty
Defines whether theStage
is resizable or not by the user. Programatically you may still change the size of the Stage. This is a hint which allows the implementation to optionally make the Stage resizable by the user.Warning: Since 8.0 the property cannot be bound and will throw
RuntimeException
on an attempt to do so. This is because the setting of resizable is asynchronous on some systems or generally might be set by the system / window manager.
Bidirectional binds are still allowed, as they don't block setting of the property by the system.- Default value:
- true
- Returns:
- the
resizable
property - See Also:
-
close
public void close()Closes thisStage
. This call is equivalent tohide()
. -
fullScreenPropertyImpl
-
fullScreenProperty
- Returns:
- the
fullScreen
property - See Also:
-
setFullScreen
public final void setFullScreen(boolean value) Sets the value of thefullScreen
property.- Property description:
- Parameters:
value
- the value for thefullScreen
property- See Also:
-
isFullScreen
public final boolean isFullScreen()Gets the value of thefullScreen
property.- Property description:
- Returns:
- the value of the
fullScreen
property - See Also:
-
setFullScreenExitHint
-
setMinWidth
public void setMinWidth(double minWidth) -
setMinHeight
public void setMinHeight(double minHeight) -
getIcons
-