简体   繁体   中英

JavaFX. Open a pop-up window before main

I have tried searching for this many times with no luck. I am writing a software where I want the user to input their resolution before moving on to the main UI, as the main UI will change size based on the resolution given. How would I open a popup window without a button event handler and then proceed to the main application?

You can just open the popup window in your start() method:

public class MyApp extends Application {

    @Override
    public void start(Stage primaryStage) {

        // make sure application doesn't exit when we close the dialog window:
        Platform.setImplicitExit(false);

        Stage popup = new Stage();
        TextField resolutionField = new TextField();
        // ... populate popup, etc...

        popup.setOnHidden(() -> {

            int resolution = Integer.parseInt(resolutionField.getText());

            // now create main UI...

            primaryStage.show();
        });

        popup.show();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM