我刚刚开始学习spring并尝试使用javafx但是我无法加载fxml。当我检查网络时,有不同的方法来加载fxml。所以,任何好友都可以帮助我,我想知道使用spring加载fxml的不同方法
Main.java
@Override
public void start(Stage stage) {
ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
ScreensConfig screens = context.getBean(ScreensConfig.class);
screens.setPrimaryStage(stage);
screens.loginDialog().show();
}
public static void main(String[] args) {
launch(args);
}
}
ScreensConfig.java
private Stage primaryStage;
public void setPrimaryStage(Stage primaryStage) {
this.primaryStage = primaryStage;
}
public void showScreen(Parent screen) {
primaryStage.setScene(new Scene(screen, 800, 500));
primaryStage.show();
}
@Bean
@Scope("prototype")
public void loginDialog() {
setNode(getNode(getClass().getResource("Login.fxml"), primaryStage, StageStyle.UNDECORATED));
}