Priyamal
Priyamal

Reputation: 2969

changing look and feel doesn't apply to jfilechooser when using spring boot

I am creating a swing application with using spring boot. and the frame that i try to use is registered as a component in the application context.

    @Bean
    public UploadForm createUploadForm(){
        return new UploadForm();
    }

this is how i started the application at first

    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);
        });
    }

but with this way file chooser appear in the same old way. but if we use new UploadForm instead of the registered bean in the context everything looks fine, jfilechooser appear in the windows look and feel format

     UploadForm uploadForm = new UploadForm();
     uploadForm.setVisible(true);

Upvotes: 0

Views: 76

Answers (1)

hkn
hkn

Reputation: 1448

You need to set the look and feel before the bean is constructed. Try to move the line UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); before context creation.

Upvotes: 1

Related Questions