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

Advanced Customization


In the programming guide section, you have seen how to create and use ProgressDialog. In this section, you will learn how to customize ProgressDialog to satisfy your requirements.

As you learn the following customization techniques, you can use the DemoUI to try it out. To launch the DemoUI program, simply double click on the progressdialog.jar.

Note: All the customization must be done after you create the progress dialog and before you call the beginTask method.

Index:

  1. Millis to Decide Pop up and Millis to Pop up
  2. Display Estimated Remaining Time
  3. Display Percentage in Progress Bars
  4. Show Animation
  5. Set Modality of the Dialog
  6. Attach a Component at the Top of the Dialog



1. Millis to Decide Pop up and Millis to Pop up

Initially, the progress dialog does not show up. After the first millisToDecideToPopup milliseconds (default 500, i.e., 0.5 second) the progress dialog will predict how long the operation will take. If it is longer than millisToPopup (default 1000, 1 second), the progress dialog then shows up.

You use the following code to configure these options:

1.	ProgressDialog progressDialog = new ProgressDialog(DemoUI.this, “”);
2.	// all the customization must be done after you create the progress dialog and before you call the beginTask method.
3.	
4.	progressDialog.millisToDecideToPopup = 400;
5.	progressDialog.millisToPopup = 2000;
6.	...
7.	progressDialog.beginTask(...
2. Display Estimated Remaining Time

By default, ProgressDialog displays the estimated remaining time. To turn it off, use:

progressDialog.displayTimeLeft = false;
3. Display Percentage in Progress Bars

To displays the percentage in the center of the progress bar, use:

progressDialog.displayPercentageInProgressBar = true;

Sample screenshot:

4. Show Animation

To enable animation, call:

progressDialog.showAnimation = true;
5. Set Modality of the Dialog

By default, the dialog is modal. To turn it off, use:

progressDialog.modal = false;
6. Attach a Component at the Top of the Dialog

To attach a component at the top of dialog, call:

progressDialog.topComponent = your component;

Sample code:

1.	...
2.	ProgressDialog progressDialog = new ProgressDialog(null, "Progress");
3.			
4.	JLabel label = new JLabel(new ImageIcon("ProgressDialog.gif"));
5.	label.setOpaque(true);
6.	label.setBackground(Color.white);
7.	progressDialog.topComponent = label;
8.					
9.	progressDialog.beginTask("Number Counting", range, true);
10.	...

Screenshot:

If you need further customization, request it here.



  

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