javaFX与spring整合方法
来源:互联网 发布:有鬼吗 知乎 编辑:程序博客网 时间:2024/05/18 08:49
目前在用JavaFx与spring结合做一个客户端程序,把javaFx的视图对应的controller交给spring管理,方法如下:
public class SpringFxmlLoader extends FXMLLoader{
private static ApplicationContext applicationContext = null;
@SuppressWarnings("rawtypes")
public Object springLoad(String url,Class cl) throws Exception{
applicationContext = StaticData.context;
try {
InputStream fxmlStream = cl.
getResourceAsStream(url);
FXMLLoader loader = this;
loader.setControllerFactory(new Callback<Class<?>, Object>() {
@Override
public Object call(Class<?> clazz) {
return applicationContext.getBean(clazz);
}
});
return loader.load(fxmlStream);
} catch (IOException ioException) {
throw new RuntimeException(ioException);
}
}
}
其中,ApplicationContext 是spring的上下文,可以通过context = new ClassPathXmlApplicationContext( new String[] { "classpath:applicationContext.xml" });
等方式获取。
下面是调用的生成controller的代码
Stage stage = new Stage();
AnchorPane root = null;
SpringFxmlLoader loader = new SpringFxmlLoader();
try {
root = (AnchorPane) loader.springLoad("view/TableView.fxml", Main.class);
TableController controller = loader.getController();
controller.setStage(stage);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
stage.setTitle("这是一个标题");
} catch (Exception e) {
e.printStackTrace();
DialogTools.error("错误", "出错了!", "查询表单数据出错!");
}
- javaFX与spring整合方法
- spring javafx整合
- JavaFX与Spring 集成
- strut2 整合spring步骤与方法
- Struts与Spring整合的方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- spring与mybatis三种整合方法
- AndroidStudio签名打包爬坑记
- SVN服务器的本地搭建和使用(一)
- SVN服务器搭建和使用(二)
- ASP.NET MVC中注册Global.asax的Application_Error事件处理全局异常
- Linux下的SVN服务器搭建
- javaFX与spring整合方法
- SVN服务器搭建和使用(三)
- 使用SourceTree git项目详解
- Linux 操作MySQL常用命令行
- Linux目录详细说明大全, 方便你以后合理规划及管理
- Linux crontab定时执行任务 命令格式与详细例子
- Linux Shell脚本编写规范、例子
- 如何解决跨域问题?
- Linux 常用命令