title: Show an indeterimante progress bar in a JDialog in a thread and run a task in another thread concurrently
body: <p>When a user clicks a button, a long task of approximately 10 seconds will run. During this time I want to show a progress bar to the user. But the main thread has to wait for the worker thread to finish because the worker thread will set a variable that the main thread will use. If I don't wait the worker thread I will get a <code>NullPointerException</code> when using the variable. So after the worker thread finishes, I will also close the progress bar dialog. </p>
  
  <p>When I wait for the worker thread using <code>join()</code> the progress bar dialog shows (interestingly without the progress bar though) and hangs there.</p>
  
  <pre><code>Thread runnable = new Thread() {
  
      public void run() {
          try {
              System.out.println("thread basladi");
              threadAddSlaveReturnMessage = request.addSlave(
                  ipField.getText(), passField.getText(), 
                  nicknameField.getText());
              System.out.println("thread bitti");
  
          } catch (LMCTagNotFoundException e) {
              e.printStackTrace();
          }
  
      }
  };
  
  Thread runnable_progress = new Thread() {
  
      public void run() {
  
          JTextArea msgLabel;
          JDialog dialog;
          JProgressBar progressBar;
          final int MAXIMUM = 100;
          JPanel panel;
  
          progressBar = new JProgressBar(0, MAXIMUM);
          progressBar.setIndeterminate(true);
          msgLabel = new JTextArea("deneme");
          msgLabel.setEditable(false);
  
  
          panel = new JPanel(new BorderLayout(5, 5));
          panel.add(msgLabel, BorderLayout.PAGE_START);
          panel.add(progressBar, BorderLayout.CENTER);
          panel.setBorder(BorderFactory.createEmptyBorder(11, 11, 11, 11));
  
          dialog = new JDialog(Frame.getFrames()[0], "baslik", true);
          dialog.getContentPane().add(panel);
          dialog.setResizable(false);
          dialog.pack();
          dialog.setSize(500, dialog.getHeight());
          dialog.setLocationRelativeTo(null);
          dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
          dialog.setAlwaysOnTop(false);
          dialog.setVisible(true);
          msgLabel.setBackground(panel.getBackground());
      }
  };
  
  runnable.start();
  System.out.println("runnable start");
  runnable_progress.start();
  System.out.println("progress start");
  runnable.join();
  System.out.println("runnable join");
  runnable_progress.join();
  System.out.println("progress join");
  
  
  if (threadAddSlaveReturnMessage.equalsIgnoreCase("OK")) {
      fillInventoryTable(inventoryTable);
      JOptionPane.showMessageDialog(this, messages.getString("centrum.addslavepanel.SUCCESS"), null, JOptionPane.INFORMATION_MESSAGE);
  }
  </code></pre>
  
  <blockquote>
    <p>"progress join" </p>
  </blockquote>
  
  <p>doesn't get printed. </p>