I have a simple GUI program that creates a new window (which contains a JTable
) at some point in time. If the user closes the JTable
, the main application closes as well. How do I prevent this? Would it have something to do with how it handles the window closing, or should I give it it's own thread, or what?
Asked
Active
Viewed 187 times
3

mKorbel
- 109,525
- 20
- 134
- 319

Maxwell Sanchez
- 83
- 1
- 5
-
My guess is that your main thread already finished, causing the entire program to shut down when the window is closed. Can you post the (relevant parts of) your code? – Keppil Sep 02 '12 at 21:36
-
1the user can't close the JTable, but is closing the window or JFrame. JTable is a component only – Sep 02 '12 at 21:38
-
See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Sep 04 '12 at 00:58
1 Answers
7
Set one of these close operation for your JFrame
: HIDE_ON_CLOSE
or DISPOSE_ON_CLOSE
.
You are using EXIT_ON_CLOSE
.
Here is a link to the JavaDoc method you can use.

Baz
- 36,440
- 11
- 68
- 94
-
That doesn't seem to be working, still quits entire application :( – Maxwell Sanchez Sep 02 '12 at 21:34
-
Never mind, was putting it in the wrong place. Everything works, thank you so much! – Maxwell Sanchez Sep 02 '12 at 21:41