how do you create a Modal JDialog saying "loading" while a task is processing that shows after more than 3 seconds has passed?
Asked
Active
Viewed 515 times
2
-
It's pretty simple if the processing is happening in a thread separate from the UI thread. That is the preferable way to do it. Otherwise you're dong the processing in your main UI thread and having to launch a separate UI thread just to work around your architecture. – Paul Sasik Jul 25 '11 at 01:37
-
yes the task is runing in a separate thread. – KJW Jul 25 '11 at 01:56
2 Answers
5
To expand on Paul's answer, a SwingWorker would work well for running your background task. You could then display either a progress or a progress monitor, and the tutorials can help you here: How to Use Progress Bars

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
1+1 Hover: I got a bit lazy with my answer and just demoted it to a comment. – Paul Sasik Jul 25 '11 at 01:38
3
If the task is to load an InputStream
, see ProgressMonitorInputStream
.
E.G. (untested)
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(
parentComponent, message, inputStream);
ProgressMonitor pm = pmis.getProgressMonitor();
pm.setMillisToPopup(millisToPopup);
It will be necessary to load the InputStream
in a Thread
in order to avoid blocking the EDT.

Andrew Thompson
- 168,117
- 40
- 217
- 433