0

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,426
  • 6
  • 35
  • 73
Jayashri
  • 356
  • 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,426
  • 6
  • 35
  • 73
0

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
  • 20,461
  • 3
  • 50
  • 65
  • 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