SpringBoot 集成 JavaFX 主要文件(具体细节参考:Java SpringBoot 项目集成 JavaFX 简单示例 Demo):
启动类:
@SpringBootApplication
public class GeminiApplication extends AbstractJavaFxApplicationSupport {
public static void main(String[] args) {
launch(GeminiApplication.class, ModelView.class, args);
}
@Override
public void start(Stage stage) throws Exception {
stage.setOnShowing(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
System.out.println("4 - 窗口正在加载...");
}
});
stage.setOnShown(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
System.out.println("6 - 窗口加载完成!");
}
});
stage.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("5 - ChangeListener 窗口高度变化监听");
}
});
super.start(stage);
}
}
View对象:
@FXMLView(value = "/view/ModelView.fxml", title = "ModelView")
public class ModelView extends AbstractFxmlView {
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
System.out.println("1 - setApplicationContext");
super.setApplicationContext(applicationContext);
}
@Override
public Parent getView() {
System.out.println("2 - getView");
return super.getView();
}
}
controller:
@Slf4j
@FXMLController
public class ModelViewController implements Initializable {
/**
* 初始化加载
* @param location
* @param resources
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
System.out.println("3 - Initializable");
}
}
输出结果:
1 - setApplicationContext
2 - getView
3 - Initializable
4 - 窗口正在加载...
5 - ChangeListener 窗口高度变化监听
6 - 窗口加载完成!