The Stage class in JavaFX represents a top-level window. Every JavaFX application receives a primary Stage from the runtime, and you place a Scene inside it to show your user interface. Additional stages give you extra windows, dialogs and popups.
Think of the hierarchy as three layers: Stage is the window, Scene is the content area inside the window, and nodes such as buttons and layouts make up the scene graph.
javafx.stage.Stage extends Window. It controls the title bar, size, position, whether the window can be resized, and its relationship to other windows. A Stage can hold only one Scene at a time, though you can swap scenes at run time to change screens.
| Class | Role |
|---|---|
Stage | The operating system window |
Scene | Container for the node tree shown in a stage |
Node | Any visual element, such as Button or VBox |
JavaFX calls start(Stage primaryStage) on the JavaFX Application Thread after it creates the primary stage. You set up the scene and call show().
JavaFX is no longer bundled with the JDK, so add the OpenJFX modules to your build, for example with the org.openjfx:javafx-controls dependency and the javafx-maven-plugin, then run mvn javafx:run.
Use show() to display a stage without blocking, and showAndWait() to open it and block the caller until it closes, which is how modal dialogs work. Call close() or hide() to dismiss it. Always create and change a stage on the JavaFX Application Thread; use Platform.runLater when you are on another thread.
You choose the window decoration with StageStyle, and it must be set before the stage is shown for the first time.
| StageStyle | Result |
|---|---|
DECORATED | Normal window with title bar (default) |
UNDECORATED | No title bar or borders |
TRANSPARENT | Undecorated with a transparent background |
UTILITY | Minimal title bar, for tool windows |
UNIFIED | Platform-specific unified toolbar look |
Modality decides whether the stage blocks input to other windows.
Modality.NONE does not block anything, WINDOW_MODAL blocks only the owner window, and APPLICATION_MODAL blocks every other window in the application. initOwner, initModality and initStyle must be called before the stage is first shown.
Open a second window by creating a new Stage. To change screens inside one window, replace the scene or, more cheaply, replace the root of the existing scene.
Replacing the root keeps size, stylesheets and window state, which avoids flicker compared with creating a new Scene. The JavaFX application ends when the last stage closes, unless you disable that with Platform.setImplicitExit(false).
A stage is the window itself. A scene is the content shown inside that window, and a stage displays only one scene at a time.
As many as you need. The first one is created by JavaFX and passed to start(), and you create the rest yourself with new Stage().
Create a new Stage, call initModality(Modality.APPLICATION_MODAL) and initOwner(...), then show it with showAndWait().
You usually changed the stage on a thread other than the JavaFX Application Thread, or you called initStyle or initModality after the stage was already shown. Move the call to Platform.runLater or earlier in the setup.
Stage is the top-level window of a JavaFX application. You give it a Scene, set its title, size, style and modality, and show it on the JavaFX Application Thread. Use the primary stage for the main window, new stages for dialogs and extra windows, and swap the scene root to move between screens.