2

how do you create a Modal JDialog saying "loading" while a task is processing that shows after more than 3 seconds has passed?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
KJW
  • 15,035
  • 47
  • 137
  • 243
  • 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 Answers2

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
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