Java Glossary : progress monitoring

CMP home Java glossary home Menu no menu Last updated 2004-06-28 by Roedy Green ©1996-2004 Canadian Mind Products

Java definitions: 0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

You are here : home : Java Glossary : P words : progress monitoring.

progress monitoring
If you are doing something that will take a while it is polite to let the user know how you are getting along. One way to do this in with progress status messages indicating the stage of work you have reached and another is progress bars, thermometers that indicates percent completed. The tricky problem with progress notification is if you are using the default thread, nothing ever gets painted because the repaint events will only be handled by the default thread only after you finish the lengthy computation or task you are progress monitoring.

How do you solve this problem? You can use a second thread and send progress notes to the Swing thread via SwingUtilities.invokeLater. This has the advantage of leaving the GUI fully functionaly while you perform your lengthy computation.

Another simpler technique is to use the javax.swing.JComponent.paintImmediately method which will immediately repaint the component and its children using the current thread. You could use it to implement a progress bar or a progress status label. There are two versions: one takes four integers (x, y, width, height) and the other takes a Rectangle instance. You can easily get the Rectangle by calling getBounds on the component and passing that into the paintImmediately method. This techique has the disadvantage of freezing the GUI, except for the progress indicators, during the time you are performing your lengthy computation.

There are two built-in progress classes JProgressBar, and ProgressMonitor. ProgressMonitor only pops up if this particular operation will take substatial time. Since they are Swing components, they are not thread safe. You must update them from the SWing thread via SwingUtilities.invokeLater. You must do your actual work on some other thread that the Swing thread, or they will never be updated. You can dynamically change the min and max on the fly as well at the value that repsents how much has been accomplished. progressBar.setIndeterminate( true ) lets you put up a temporary busy display when you temporarily have no idea how far through the work you are. Sun has a tutorial on progress bars.


CMP logo
CMP_home
home
Canadian Mind Products CSS
HTML Checked!
ICRA ratings logo
mindprod.com IP:[24.87.56.253]
Your IP:[80.134.30.163]
You are visitor number 1003.
Please send errors, omissions and suggestions
to improve this page to Roedy Green.
You can get a fresh copy of this page from: or possibly from your local J: drive mirror:
http://mindprod.com/jgloss/progress.html J:\mindprod\jgloss\progress.html