Package javafx.stage

Class Stage

java.lang.Object
javafx.stage.Window
javafx.stage.Stage
All Implemented Interfaces:
EventTarget

public class Stage extends Window
The JavaFX 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.

The JavaFX Application Thread is created as part of the startup process for the JavaFX runtime. See the Application class and the Platform.startup(Runnable) method for more information.

Some Stage properties are read-only, even though they have corresponding set methods, because they can be changed externally by the underlying platform, and therefore must not be bindable. Further, these properties might be ignored on some platforms, depending on whether or not there is a window manager and how it is configured. For example, a platform without a window manager might ignore the iconified property.

Style

A stage has one of the following styles:

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:

A visual rendering
 of a JavaFX Stage on Windows

produces the following on Mac OSX:

A visual rendering
 of a JavaFX Stage on Mac OSX

produces the following on Linux:

A visual rendering
 of a JavaFX Stage on Linux

Since:
JavaFX 2.0