简体   繁体   中英

How to open new javafx fxml window under if condtition?

I create a simple login form to checking username and password. I did it and my problem is while checking the username and password is correct open new fxml window. Can anyone drop some simple code to solve it.

So, below is just an example to get you started but what I usually do is I create some sort of a stage factory so that I don't have a lot of duplicate code. Let me know if you have any questions.

My example:

if(/*your if condition*/){
    YourController controller = new YourController();
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(fxmlPath));
    loader.setController(controller);
    Parent root = loader.load();
    Scene scene = new Scene(root, width, height, Color.WHITE);
    Stage stage = new Stage();
    stage.setX(xPos);
    stage.setY(yPos);
    stage.setScene(scene);
    stage.show();
}

Edit, I felt nice today but I do agree with the first comment that you received. Remember to read through the guide lines next time.

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