使用 spring 引导时更改外观不适用于 jfilechooser
changing look and feel doesn't apply to jfilechooser when using spring boot
我正在使用 spring boot 创建一个 swing 应用程序。我尝试使用的框架在应用程序上下文中注册为组件。
@Bean
public UploadForm createUploadForm(){
return new UploadForm();
}
这就是我最初启动应用程序的方式
public static void main(String[] args) throws Exception{
SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(Application.class);
springApplicationBuilder.headless(false);
ConfigurableApplicationContext context = springApplicationBuilder.run(args);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EventQueue.invokeLater(() -> {
UploadForm uploadForm = context.getBean(UploadForm.class);
uploadForm.setVisible(true);
});
}
但是通过这种方式,文件选择器以相同的旧方式出现。但是如果我们在 contextnew UploadForm 而不是 registered bean =27=] 一切看起来都很好,jfilechooser 出现在 windows 外观格式中
UploadForm uploadForm = new UploadForm();
uploadForm.setVisible(true);
您需要在构造 bean 之前设置外观。尝试在创建上下文之前移动行 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
。
我正在使用 spring boot 创建一个 swing 应用程序。我尝试使用的框架在应用程序上下文中注册为组件。
@Bean
public UploadForm createUploadForm(){
return new UploadForm();
}
这就是我最初启动应用程序的方式
public static void main(String[] args) throws Exception{
SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(Application.class);
springApplicationBuilder.headless(false);
ConfigurableApplicationContext context = springApplicationBuilder.run(args);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EventQueue.invokeLater(() -> {
UploadForm uploadForm = context.getBean(UploadForm.class);
uploadForm.setVisible(true);
});
}
但是通过这种方式,文件选择器以相同的旧方式出现。但是如果我们在 contextnew UploadForm 而不是 registered bean =27=] 一切看起来都很好,jfilechooser 出现在 windows 外观格式中
UploadForm uploadForm = new UploadForm();
uploadForm.setVisible(true);
您需要在构造 bean 之前设置外观。尝试在创建上下文之前移动行 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
。