Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JProgressBar is not updating even in new Thread !

807588Mar 24 2009 — edited Mar 27 2009
Hello 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}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 24 2009
Added on Mar 24 2009
10 comments
637 views