Swing UI Problem

Hi.

I have a problem with swing UI update. The sample code part is given below. When I press the button, it first sets the progress bar value to 50 and then after completing the time consuming task it sets it to 100. The problem is my progress bar is being showed only when it exits from the actionPerformed function. What I want it to see is the progress bar at 50% while the 20 sec task is being executed. Any suggestions ?

void nextButton_actionPerformed(ActionEvent e)

{

myProgressBar.setValue(50%);

// a set of code which takes about 20 seconds to

// execute

myProgressBar.setValue(100%);

}

Thanks,

JP

[702 byte] By [jpsathiadas] at [2007-9-26 1:57:34]
# 1
maybe you need to call repaint() on myProgressBar? just a suggestion. don't know if it will help
audus at 2007-6-29 3:14:19 > top of Java-index,Archived Forums,Java Programming...
# 2
Hi,The Progress bar needs to be run in it's own thread.HTH,Fintan
CelticPhantom at 2007-6-29 3:14:19 > top of Java-index,Archived Forums,Java Programming...
# 3

Hi there

Look I have not tried it before but I've read about it. If you want to create a progress Bar then you have to create a Thread for the progress Bar that starts to live when the GUI is initiated. Then you divide the code that has to be processed and reflected in your progress Bar into sections and for each of the sections you give a Thread and when its Thread is finished then you fill your progress Bar to the point that will show how far the job is completed.

I hope this will help you as I said I have not tried it but this is what I read.

Ciao

Chardenay at 2007-6-29 3:14:19 > top of Java-index,Archived Forums,Java Programming...