Progress Monitor Dialog - an Improved Java Swing ProgressMonitor for long running process

Create Indeterminate Progress Dialog

Next section

Sometimes, it is hard or impossible to tell the amount of total work. In this case, you can use an indeterminate progress dialog.

The code below illustrates how to use an indeterminate progress dialog:

1.	ProgressDialog progressDialog = new ProgressDialog(null, "Progress");
2.	progressDialog.beginTask("Number Counting", -1, true);
3.			
4.	for(int i=0; i<range; i++) {
5.		if(progressDialog.isCanceled()) {
6.			System.out.println("CANCELED.");
7.			break;
8.		}
9.	
10.		System.out.println(i + " of " + range);
11.		Thread.sleep(500);
12.	}
13.			
14.	progressDialog.finished();

When you call the beginTask method, you specify -1 as the amount of work units. When you finishes the task, use finished method to notify the progress dialog that the task completes. The corresponding UI is show below:

The progress bar displays animation to indicate that work in progress.



  

ALL RIGHTS RESERVED BY JACK LI © 1998 - 2010. Terms of Use | Privacy Policy