Question

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?

Was it helpful?

Solution

Take a look at the Swing tutorial about splash screens which contains sample code doing exactly what you want

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top