使用进度条初始化应用程序和初始屏幕(Swing) [英] Initialization of application and splash-screen with progress bar (Swing)

查看:294
本文介绍了使用进度条初始化应用程序和初始屏幕(Swing)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已为我们的应用程序构建了一个启动画面。当应用程序的初始化在主线程中时,它工作正常,但是当我在EDT中移动初始化(主方法中的SwingUtilities.invokeLater)时,由于阻止EDT,进度条和信息标签不会重新绘制。我知道,使用invokeLater可以帮助我重新绘制GUI。但我的问题是:在单独的部分(遗留代码)中拆分应用程序的初始化真的很难。即使我这样做,我也会得到一个丑陋的matroshka代码(在invokeLater中调用六次invokeLater)。

We have built a splash screen for our application. It works fine when the initialization of application is in the main thread, but when I move the initialization in EDT (SwingUtilities.invokeLater in main method), the progress bar and info label do not repaint itself due to blocking of EDT. I know, that using of invokeLater can help me to repaint the GUI. But my problem is: it's really hard to split the initialization of aplication in separate pieces (legacy code). And even if I do it, I will get a ugly matroshka-code (six times invokeLater in invokeLater).

我应该选择哪种解决方案:

Which solution should I prefer:


  1. 在主线程中保留初始化(我当前的决定)

  2. 尝试将其移至EDT(如果可能)并获取matroshka代码

  3. 每次我更新启动画面时,使用Foxtrot lib在EDT中提供非阻塞睡眠(它工作正常 - 启动画面可以重新绘制自己,但对我来说这是一个黑客攻击)

可能有人有更好的解决方案吗?

Probably someone has a better solution?

PS我已经在这里读过一些类似的问题,但没有找到对我有用的东西。

P.S. I've already read some similar questions here but did not found anything helpful for me.

推荐答案

将源数据加载到 doInBackground() SwingWorker publish()中间结果;在 process()中更新GUI组件的模型。当数据继续加载时,将显示初始结果,GUI将名义上起作用。 实际加载数据的时间将保持不变,但感知的时间将会更短。

Load the source data in the doInBackground() method of a SwingWorker, and publish() intermediate results; update the GUI component's model in process(). While data continues to load, initial results will be displayed and the GUI will function nominally. The real time to load data will remain unchanged, but the perceived time will be less.

这篇关于使用进度条初始化应用程序和初始屏幕(Swing)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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