1

I'm using netbeans 7.1.1, to create a JFrame. I want to automatically dispose the JFrame 5 seconds after calling setVisible() . How can I do this?

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77
Jayashri
  • 366
  • 4
  • 13
  • 25

2 Answers2

3

HINT

Use Swing Timer to wait for 5 seconds before calling setVisible(false) or dispose() whichever way you want it implemented. Hidden/Disposed

Mukul Goel
  • 8,387
  • 6
  • 37
  • 77
1

Did u do your research on this? Seems straight forward.

new Timer().schedule(new TimerTask() {
    public void run() {
          // this should be final
          jframe.dispose();
    }
}, 5000);
shazin
  • 21,379
  • 3
  • 54
  • 71
  • Please Promote research !! avoid giving cooked up code samples. – Mukul Goel Nov 05 '12 at 11:47
  • 7
    Seems straightforward but with this approach you violate the Swing threading rules. Either wrap that `dispose` call in an `SwingUtilities.invokexxx` call or use a `javax.swing.Timer` – Robin Nov 05 '12 at 11:47