I tried to animate the jprogressbar in a method doUploadAction(), then start a thread to upload a image, and stop the jprogressbar indeterminate animation after the thread finish, but it did not work. The progress bar did not do anything at all.
What is wrong with it? Do I need to start a new thread for the progressbar and do the upload in current thread?
Read the JProgressBar API and follow the link to the Swing tutorial on "How to Monitor Progress" for a working example.
Joined: Apr 10, 2009
Thank you Rob. I already read that. The progressbar is in a pane, not a pop up dialog which will be used by progressMonitor. Also, since i am using java 1.5, there is not SwingWorker which is new for java 1.6 and I can not use Task. So my way will not work? What is the problem with it?
Why are you creating an anonymous Runnable, then call its run() method? That doesn't create a thread or anything; you might as well just place the contents of the run() method there.
If you cannot use SwingWorker (I suggest you upgrade to Java 6; Java 5.0 is getting quite old already!) you should use a regular thread, and do all interactions to the GUI using EventQueue.invokeLater or EventQueue.invokeAndWait.