当我尝试在单击Jbutton时调用方法updateProgressBar方法但是没有显示进度时,只显示空白对话框,直到值达到100%。
following is the method from class ProgressBar which will display Jdialogue box with progress bar.
public void updateProgressBar(int i)
{
pb.setString("Processing " + i + "%");
pb.setValue(i);
try
{
Thread.sleep(100);
}catch(Exception e)
{
e.printStackTrace();
}
}
following is how it is called from Jframe.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
ProgressBar pd=new ProgressBar();
int i=1,j=100;
pd.setVisible(true);
while (i<=50)
{
pd.updateProgressBar(i);
i++;
}
pd.dispose();
}