[teratail] JavaFXの画面遷移について (2017/07/24) [2020/07/21]
public static <T extends Initializable> void transitionTo(String fxmlFilename, BiConsumer<Stage, T> callback) {
try {
FXMLLoader loader = new FXMLLoader(MyApp.class.getResource(fxmlFilename));
Parent root = loader.load();
T controller = loader.getController();
Stage stage = theApp.primaryStage;
stage.setScene(new Scene(root));
callback.accept(stage, controller);
stage.show();
} catch (Exception e) {
e.printStackTrace();
Platform.exit();
}
}