title: How to close JOptionPane automatically?
body: <p>I have a <code>Thread</code> running and in the time while the <code>thread</code> working i want to display a <code>JOptionPane.showMessageDialog</code> saying that the application is working and after thread is stopped, <code>JOptionPane</code> will close automatically and <code>OK</code> button will be deactivated the whole time. My Main code :</p>
  
  <pre><code>class Index {
  public static void main(String args[]) {
     NewThread ob1 = new NewThread("One");
     NewThread ob2 = new NewThread("Two");
     NewThread ob3 = new NewThread("Three");
      System.out.println("Thread One is alive: "+ ob1.t.isAlive());
      System.out.println("Thread Two is alive: "+ ob2.t.isAlive());
      System.out.println("Thread Three is alive: "+ ob3.t.isAlive());
     while (ob1.t.isAlive()){
      JOptionPane.showMessageDialog(null,"Thread One is alive");
     }
      System.out.println("Thread One is alive: "+ ob1.t.isAlive());
      System.out.println("Thread Two is alive: "+ ob2.t.isAlive());
      System.out.println("Thread Three is alive: "+ ob3.t.isAlive());
      System.out.println("Main thread exiting.");
  }}
  </code></pre>
  
  <p>And when i run it the <code>JOptionPane</code> display but he won't close  automatically unless i pressed <code>OK</code> button.</p>
  
  <pre><code>class NewThread implements Runnable {
  String name; 
  Thread t;
      NewThread(String threadname) {
          this.name = threadname;
          this.t = new Thread(this, name);
          System.out.println("New thread: " + t);
          this.t.start(); // Start the thread
      } 
  public void run() {
      try {
      for(int i = 5; i &gt; 0; i--) {
          System.out.println(name + ": " + i);
          Thread.sleep(1000);
          }
          } catch (InterruptedException e) {
          System.out.println(name + " interrupted.");}
          System.out.println(name + " exiting.");
  }}
  </code></pre>