简体   繁体   中英

Splash screen showing progress of GUI being built in Event Dispatch Thread

According to http://www.javaworld.com/javaworld/jw-08-2007/jw-08-swingthreading.html?page=5 all GUI operations should be executed in Event Dispatch Thread.

While I understand the reasons why Swing was designed with single threaded model in mind, I can't figure out how to solve the following problem:

Let's have a method called buildGui() which initializes main GUI of the application. Call to buildGui() method takes 10 seconds to return.

Let's have another method called splashScreen() which shows the JDialog with indeterminate JProgressBar inside. The purpose of the JDialog is obvious: it gives user feedback that application is loading resources, initializing components, etc.

Now, if my program calls:

splashScreen();   // build and show splash screen in EDT
buildGui();       // build main GUI in EDT

the splash screen is freezed for 10 seconds, because it waits for buildGui() to finish.

Do you have any ideas how to show splash screen which depicts the status of GUI initialization ( buildGui() ) while following Swing's single threaded model?

Use AWT for splash screens, so they can be loaded prior to loading the Swing package. The plug-in's own SplashScreen is pure AWT. See also this question re. use of SplashScreen & the EDT .

While I'm typically saying 'this millennium, use Swing components', it makes a lot of sense to use AWT for a splash.

看一下有关初始屏幕Swing教程,其中包含示例代码,可以完全满足您的要求

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM