title: Activate Progress Bar outside the main using data claculating in the background
body: <p>i'm trying to activate progress bar that showing the advance of the "for loop" i have while i reading my files and writes them to excel file.
  the problam is that the bar don't update to the user until the end of the for loop in each way i tried. what is the right way to do this? is it possible to activate progress bar in the middle of the MyPanel class?</p>
  
  <p>i have the next classes:
  Tester(contain the main) , MyPanel , LogFileReader , DefectFileReader.</p>
  
  <p><em>Tester</em></p>
  
  <pre><code>public class Tester {
  
      public static void main(String[] args){
  
          JFrame frame = new JFrame("Analayzer GUI");
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(450, 300);
          frame.setLocationRelativeTo(null);
          MyPanel p = new MyPanel();
          frame.add(p);
          frame.setVisible(true);
  
      }
  }
  </code></pre>
  
  <p><em>My Panel</em> (only the relevant code)</p>
  
  <pre><code>public class MyActionListener implements ActionListener  
  {
      public void actionPerformed(ActionEvent click) 
      {
          /*...........(code irelevant).......*/
  
          if(click.getSource() == analayze){
              Boolean valid = isValidToStart();
              if(valid == true){
                  try{
                  fos = new FileOutputStream("c:/temp/analayze.xlsx");
              if(DFloaded == true){
                  try {
                      pbar.repaint();
                      DF = new File[DFLIST.length];
                      dfReader = new DefectFileReader[DFLIST.length];
                      docArray = new Document[DFLIST.length];
                      for(int i = 0 ; i &lt; DFLIST.length ; i++){
                       /******* This is where i want to update my bar according to (i/DFList.length) ********/
                          System.out.println("i'm sending the file down here to parse from file to document");
                          System.out.println(DFLIST[i].getAbsoluteFile());
                          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                          DocumentBuilder db = dbf.newDocumentBuilder();
                          docArray[i] = (Document) db.parse(DFLIST[i]);
                          docArray[i].getDocumentElement().normalize();
                          dfReader[i] = new DefectFileReader(DFLIST[i] , docArray[i]);
                          dfReader[i].getRunsIndex();
                          totalDuration = sumTimes(dfReader[i].inspectionDuration());
                          if(i==0){
                              firstWriteToExcel(dfReader[0], sheet, workbook, fos);
                              writeToExcel(dfReader[0], sheet, workbook, fos);
                          }
                          if(i!=0)
                              writeToExcel(dfReader[i] , sheet ,  workbook , fos );
                          repaint();
                      if(INPloaded == true){
  
                      }
                      DFLIST[i] = null;
                      dfReader[i].clearDfReader();
                      docArray[i] = null;
                      System.gc();
                     }
                  }
                     catch(Exception e ) {
                        System.out.println(e);
                        System.exit(0);
                     }
              }
  
              row = sheet.createRow(rowIndex);
              totalDuration = sumTimes("00:00:00");
              if(inspectionDuration.getState() == true){
              row.createCell(cellIndex - 1).setCellValue(totalDuration);
              row.getCell(cellIndex - 1).setCellStyle(csForFirstWrite);
              }
              ((Workbook) workbook).write(fos);
              workbook.close();
              JOptionPane.showMessageDialog(null, "Your data has been analyze!\n you can find the result in c:\\temp");
              System.exit(0);
  
          }catch(Exception e){
              e.printStackTrace();
          }
  
      }
  }
  </code></pre>