进度条不能在java中使用Jframe

时间:2017-11-27 03:30:52

标签: java swing

当我尝试在单击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();


    }                    

0 个答案:

没有答案