Possible Duplicate:
Java GUI JProgressBar not painting
Can a progress bar be used in a class outside main?
I am using Netbeans drag and drop to do an application. I will get input from user and use the input to run my algorithm. The algorithm will take different time to run and then show its result in a new frame. While waiting the algorithm to run, I wish to add in a progress bar. I add in the below code when the user click the button submit input.
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {   
    final JProgressBar bar = new JProgressBar(0,250000);
    bar.setValue(1000);
    bar.setIndeterminate(false);
    JOptionPane jO = new JOptionPane(bar);
    Thread th = new Thread(){
    public void run(){
        for(int i = 1000 ; i < 250000 ; i+=10000){
           bar.setValue(i);
            try {
                Thread.sleep(100);
           } catch (InterruptedException e) {
            }
        }
    }
};
th.start();
final JDialog dialog = jO.createDialog(jO,"Experiment X");
dialog.pack();
dialog.setVisible(true);
//Algorithm goes here
The progressbar do show up and run.But when the progress bar value is update until the end, only my algorithm run. I see through others example, but I not really understand how it works.
Can someone tell me where I got wrong?
 
     
    