Does Guice Build Swing Components Outside of UI Problem?

I am working on a Java Swing application with Google Guice as an IOC container. Everything works very well. There are some user interface issues. When the standard L & F is replaced with Pushing pixels, the L & F application does not start due to the creation of Guice Swing components outside the user interface flow.

Is there a way to tell Guice to create Swing components in a user interface thread?

Perhaps I should create custom providers that will return Swing components after I SwingUtilities.invokeAndWait(Runnable)create them.

I don't like the idea of ​​running the entire application in a user interface thread, but maybe this is just the perfect solution.

+5
source share
3 answers

IMO, you should not create components using Guice, but services, which in turn will create your components. After you enable the service, it should be easy for you to make sure that the component is being created on the EDT (using invokeAndWait)

+5
source

You might want to check out my Guts-GUI project (the Swing application platform is built on Guice). The Guts-GUI ensures that your components, even those created by Guice, are created in EDT.

Guice , , EDT. , Guice Scopes ( , ), , - Scope , .

- , Guice Injector EDT ( SwingUtilities.invokeAndWait invokeLater). , Guts-GUI . , Guice, EDT.

, , Guice Swing, (, Injector.getInstance(...)) EDT.

+1

In fact, Swing is not multithreaded and requires running in EDT. As a result, yes, your components must be prepared in EDT by calling invokeAndWait.

0
source

All Articles