javafx IllegalArgumentException (is already set as root of another scene)

后端 未结 1 1409
既然无缘
既然无缘 2021-01-18 14:14

I have problem with changing scenes in my application which looks like

Main screen > Login screen

I am storing screens in main file as <

相关标签:
1条回答
  • 2021-01-18 14:27

    The exception is pretty self-explanatory: the anchor pane cannot be the root of two different scenes. Instead of creating a new scene every time, just replace the root of the existing scene:

    @FXML
    private void LogIn(ActionEvent event) {
        Button button = (Button) event.getSource();
        Scene scene = button.getScene();
        Parent root = MyApplication.pages.get("LoginPage");
        scene.setRoot(root);
    }
    
    0 讨论(0)
提交回复
热议问题