JProgressBar is not updating even in new Thread !
807588Mar 24 2009 — edited Mar 27 2009Hello every buddy....
I'm new to SDN and I hope I'll enjoy being an active member.
I've a problem with updating JProgressBar in actionPerformed method. I know that GUI can not be updating in the event dispatching thread, so, I created a new class to show the JProgress bar in a separate thread as follows:
{color:#333399}import javax.swing.JProgressBar;
import javax.swing.Frame;
public class ProgressBar
{
public ProgressBar()
{
new Thread(new Runnable()
{
public void run()
{
showProgressBar();
}
}).start();
}// End of constructor
private void showProgressBar()
{
JProgressBar pb = new JProgressBar(0, 100);
pb.setPainted(true);
JFrame f = new Frame();
f.setSize(250, 100);
f.getContentPane().add(pb);
f.setVisible(true);
while( Crypt.done == false)
{
pb.setValue( Crypt.percentageCompleted );
}
f.dispose();
f = null;
}// End of showProgressBar method
} // End of ProgressBar class
{color}{color:#000000}I create an objmect of the above class inside another class called Crypt. when a button is clicked actionPerformed is invoked I do:
ProgressBar progress = new ProgressBar();
the frame f shows, but the JProgressBar never shows!
Can anyone help me?
with best wishes{color}