0
我有问题,我的应用程序不断变化的场景看起来像的JavaFX抛出:IllegalArgumentException(已被设为另一个场景根)
Main screen > Login screen
我存储在主文件屏幕为hashmap<String, Node>
,一切都很好,直到我去从登陆界面到主屏幕回来,想再次加载登录界面,这里是例外,代码:
java.lang.IllegalArgumentException: [email protected][styleClass=root]is already set as root of another scene
public static final HashMap<String, Parent> pages = new HashMap<>();
@FXML
private void LogIn(ActionEvent event) {
Button button = (Button) event.getSource();
Stage stage = (Stage) button.getScene().getWindow();
if(stage.getScene() != null) {stage.setScene(null);}
Parent root = MyApplication.pages.get("LoginPage");
Scene scene = new Scene(root, button.getScene().getWidth(), button.getScene().getHeight());
stage.setScene(scene);
}
它,当我创建工程新anchorpane
Parent root = new AnchorPane(MyApplication.pages.get("LoginPage"));
但我想知道为什么它给了我一个异常,如果我正在同台
真的感谢这就是解决我的问题 –
@JasonBourne,你应该纪念这个问题的正确答案。 – Kerry