KJW
KJW

Reputation: 15251

Create Modal JDialog while things are processing

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

Upvotes: 2

Views: 522

Answers (2)

Andrew Thompson
Andrew Thompson

Reputation: 168845

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.

Upvotes: 3

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285405

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

Upvotes: 5

Related Questions