我想做的是在我的程序加载某些内容时出现一个小的启动屏幕。这就是我所拥有的:
SplashScreen.showSplashScreen();
// Do stuff that takes time.
SplashScreen.hideSplashScreen();
所有 showSplashScreen() 方法所做的就是在屏幕中间创建一个新的 JWindow 并使其可见。
现在,此代码是从事件调度线程调用的,因此当调用 showSplashScreen() 方法时,直到线程完成后我才看到 JWindow,到那时,我不再需要该窗口了。在我等待时显示此启动屏幕的最佳方法是什么?
What I am trying to do is have a small splash screen appear while my program is loading something. This is what I have:
SplashScreen.showSplashScreen();
// Do stuff that takes time.
SplashScreen.hideSplashScreen();
All the showSplashScreen() method does is create a new JWindow in the middle of the screen and make it visible.
Now this code is called from the event dispatching thread, so when the showSplashScreen() method is called, I don't get to see the JWindow until the thread has finished, which by then, I don't need the window anymore. What would be the best way to go about showing this splash screen while I was waiting?
发布评论
评论(2)
不确定这是否是“最好的方法”,但我之前使用过的一种机制是在 EDT 以外的线程上进行初始化,但使用
SwingUtilities.invokeAndWait
。这样,即使您的初始化速度很快(如果您希望发生这种情况),您至少也能看到启动屏幕。所以在你的初始化线程上,你可以:
Not sure if this is the "best way", but a mechanism I've used before is to do your initialisation on a thread other than the EDT, but show your splash screen using
SwingUtilities.invokeAndWait
. That way, you'll at least get to see the splash screen even if your initialisation is quick (if that's what you want to happen).So on your init thread, you go:
1.6 中引入了一个 java.awt.SplashScreen 类,尝试使用它吗?
There is a
java.awt.SplashScreen
class that was introduced in 1.6, tried using that?