Guice在UI线程问题之外创建Swing组件? [英] Guice creates Swing components outside of UI thread problem?

查看:140
本文介绍了Guice在UI线程问题之外创建Swing组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Guice作为IOC容器处理Java Swing应用程序。事情进展顺利。有一些UI问题。当用Pushing像素替换标准L& F由于在UI线程之外创建Guice的Swing组件,物质L& F应用程序没有运行。

I'm working on Java Swing application with Google Guice as an IOC container. Things are working pretty well. There are some UI problems. When a standard L&F is replaced with Pushing pixels Substance L&F application is not running due to Guice's Swing components creation outside of UI thread.

有没有办法告诉Guice在UI线程中创建Swing组件?

Is there a way to tell Guice to create Swing components in the UI thread?

也许我应该创建自定义提供程序,它将在 SwingUtilities.invokeAndWait(Runnable)之后返回Swing组件创建它们。

Maybe I should create custom providers which will return Swing components after SwingUtilities.invokeAndWait(Runnable) creates them.

我不喜欢在UI线程中运行整个应用程序的想法,但也许它只是一个完美的解决方案。 / p>

I don't like the idea of running the whole application in UI thread, but maybe it's just a perfect solution.

推荐答案

IMO你不应该使用Guice创建组件,而是应该创建组件的服务。一旦你注入了服务,就应该很容易确保在EDT上创建组件(使用 invokeAndWait

IMO you should not create components using Guice but services which in turn will create your components. Once you have you service injected it should be easy to make sure that component creation happens on EDT (using invokeAndWait )

这篇关于Guice在UI线程问题之外创建Swing组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆