I have two JFrames opened simultaneously (by clicking certain button in the main Frame I open second Frame). I can of course exit whole program by clicking X on the main frame. The thing is: is there a way to close my subFrame by clicking X while the Main Frame remain opened? In the subFrame there is going certain action and I want to shut it down by click X but not closing the Main Frame at a time.
Asked
Active
Viewed 52 times
0
-
Have you set the `DefaultCloseOperation` property to `EXIT_ON_CLOSE` for the main frame? If so, don't do that – MadProgrammer May 03 '17 at 07:26
-
Do you mean you want clicking the "X" button on the **main** window while your sub-window is open to _not_ close the main window but to close the sub-window? Or did you mean you want clicking the sub-window's "X" to close just the sub-window and not the your whole program? – Kevin Anderson May 03 '17 at 07:46
-
See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson May 03 '17 at 12:20
-
I want to click sub-window's "X" just to close sub-window's operation (running game) while main window remain opened. And when i click "play button" again on my main window, sub-window would appear without previous progress. – May 03 '17 at 14:09
1 Answers
0
Write your close function like this
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)

Shadab Kazi
- 72
- 8