Search code examples
javaswinguser-interfacedispose

Close window - but don't stop program - JAVA


In my program it opens a window if an action is happened. After I have filled out information in this window, and entered a button, the window dispose().

The window is picked up in a program outside my main program, but when I close this window, my main program stops. How can I prevent this from happening?

Thanks for your help!


Solution

    1. You can set the defalaultCloseOperation property of the second frame to DO_NOTHING_ON_CLOSE or DISPOSE_ON_CLOSE

    2. Don't even use two frames. Use a modal JDialog instead for a secondary frame. See more at How to Use Dialogs. Read more about Modality. And for a good read, see The Use of Multiple JFrames, Good/Bad Practice?

    3. Forget about number 1. and go straight to 2.