javafx stage

http‮ww//:s‬w.theitroad.com

In JavaFX, the Stage class represents the top-level container for a graphical user interface (GUI) application. It is responsible for managing the window that contains the application, including its size, title, and icon.

Here are some key features of the Stage class:

  1. Title and icon: You can set the title and icon of the Stage using the setTitle() and getIcons() methods, respectively.

  2. Size and position: You can set the size and position of the Stage using the setWidth(), setHeight(), setX(), and setY() methods.

  3. Visibility: You can control the visibility of the Stage using the show() and hide() methods.

  4. Modality: You can set the modality of the Stage to specify whether it is modal or non-modal using the initModality() method.

  5. Resizing: You can control whether the user can resize the Stage using the setResizable() method.

  6. Fullscreen: You can put the Stage into fullscreen mode using the setFullScreen() method.

  7. Owner and parent: You can set the owner and parent of the Stage using the initOwner() and initParent() methods.

Here is an example of how to create and show a simple Stage in JavaFX:

import javafx.application.Application;
import javafx.stage.Stage;

public class MyApplication extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        // Set the title of the stage
        primaryStage.setTitle("My Application");

        // Set the size of the stage
        primaryStage.setWidth(400);
        primaryStage.setHeight(300);

        // Show the stage
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

In this example, we create a new Stage object called primaryStage, set its title and size, and then call the show() method to display it. The start() method is called by the JavaFX runtime when the application is launched, and the main() method simply calls the launch() method to start the application.