JavaFX + Scene Builder how switch scene

删除回忆录丶 提交于 2019-12-01 18:33:09

You can get a reference to the Scene and Window from your button reference. From there, it's up to you to decide how to you want to show the new view.

Here's how you get those references:

Scene scene = btnSignIn.getScene();
Window window = scene.getWindow();
Stage stage = (Stage) window;

You can change the view by changing the root of your Scene:

FXMLLoader loader = ... // create and load() view
btnSignIn.getScene().setRoot(loader.getRoot());

Or you can change the entire Scene:

FXMLLoader loader = ... // create and load() view
Stage stage = (Stage) btnSignIn.getScene().getWindow();
Scene scene = new Scene(loader.getRoot());
stage.setScene(scene);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!