-2

I have a main JFrame with a button that generates another JFrame. However, when I close the 2nd JFrame the main JFrame is also closed which is not what I want. What am I doing wrong?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1812379
  • 827
  • 3
  • 11
  • 22
  • You probably set default close operation to `EXIT_ON_CLOSE` on both of JFrames. – Branislav Lazic Jul 05 '13 at 23:16
  • Welcome to Stack Overflow. The only way we can tell you what you are doing wrong is if you tell us what you are doing in the first place. Please post some code so that we can help you. – Code-Apprentice Jul 05 '13 at 23:17
  • Ups...I almost forgot: http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice This question needs more attention. – Branislav Lazic Jul 05 '13 at 23:19
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) This seems better suited to a `JDesktopPane` with `JInternalFrame` objects inside. – Andrew Thompson Jul 06 '13 at 03:51

1 Answers1

2

I assume you're setting the default closing action as:

frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);

The JFrame.EXIT_ON_CLOSE constant terminates the whole program when you click the x button. You probably want to use DISPOSE_ON_CLOSE or HIDE_ON_CLOSE instead. I recommend to have a look at the JavaDoc of JFrame.

binfalse
  • 508
  • 4
  • 10
  • Thank you very much :-) `JFrame.EXIT_ON_CLOSE` was the fault. It's baked into my brain like a mantra, hence I didn't think about changing it. – user1812379 Jul 05 '13 at 23:30