|Purpose of Progress Bars||Links|
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 of paintImmediately: 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 technique 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. JProgressBar is an always-visible thermometer-like component. It has an indeterminate mode that does not display percent complete, just an animation that hints work is happening in the background. ProgressMonitor only pops up if this particular operation will take substantial time. Since they are both Swing components, they are not thread safe. You must update them from the Swing thread via SwingUtilities.invokeLater or EventQueue. invokeLater. You must do your actual work on some other thread than the Swing thread, or the progress bars will never be updated. You can dynamically change the min and max on the fly as well at the value that represents 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.
ProgressMonitorInputStream is specially designed to monitor the reading of some InputStream. This is not all that useful since InputStreams don’t divulge the total number of bytes to be read to the underlying ProgressMonitor.
To communicate between your background Thread and the Swing GUI, you use PropertyChangeEvents. You generate them with SwingWorker. setProgress. You field them with a PropertyChangeListener on your GUI that does a ProgressBar. setValue. When you use SwingWorker.setProgress, you must scale your progress to percent complete 0.. 100.
If you use SwingWorker.cancel ( false ) your SwingWorker. done() method will run even before the background thread has noticed that SwingWorker.isCancelled () is true and has terminated. The background thread keeps running for a while even after the done dialog.
This page is posted
Optional Replicator mirror
Please read the feedback from other visitors, or send your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.
Your face IP:[220.127.116.11]
You are visitor number|