Initialization of application and splash-screen with progress bar (Swing)

浪尽此生 提交于 2019-12-01 07:55:39

问题


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. Leave initialization in main thread (my current decision)
  2. Try to move it to EDT (if possible) and get matroshka code
  3. Using Foxtrot lib to provide a non-blocking-sleep in EDT each time I update the splash screen (it works fine - the splash screen can repaint itself, but it's a hack for me)

Probably someone has a better solution?

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


回答1:


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.



来源:https://stackoverflow.com/questions/23912610/initialization-of-application-and-splash-screen-with-progress-bar-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!