title: JAVA: how to make a popUp window close automatically?
body: <p>Is there a way to make a popUp window inside an application or Applet to close itself automatically after a period of time (like 5 seconds for example)?</p>
  
  <hr>
  
  <p>I've found the Solution:</p>
  
  <p>For anyone that might be looking for the same:</p>
  
  <pre><code>public static void main(String[] args) {
      JFrame f = new JFrame();
      final JDialog dialog = new JDialog(f, "Test", true);
      Timer timer = new Timer(2000, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              dialog.setVisible(false);
              dialog.dispose();
          }
      });
      timer.setRepeats(false);
      timer.start();
  
      dialog.setVisible(true); // if modal, application will pause here
  
      System.out.println("Dialog closed");
  }
  </code></pre>
  
  <p>Thanks for your answers guys.</p>