Java swing close window without exiting app

buttonexitjavaswing

I have a little frame where I ask user & password. This frame will be opened clicking over a button in a main window.

Then I have two buttons: ok and cancel.

When I click on "cancel" button, I need to close this frame without exiting the app.

How can I do that?

Best Solution

You can use either Frame.hide() or Frame.dispose(). I would also recommend to look into JDialog or JOptionPane

Correction: hide() is deprecated. SetVisible(false) should be used instead

Related Question