0

I have a class which creates a JFrame. When I click on a button in the JFrame, another JFrame in a different class opens up.

Now, when I close the second JFrame, even the first one closes up. Any ideas on preventing this? I want the first frame to remain visible.

TT.
  • 15,774
  • 6
  • 47
  • 88
Akshay
  • 25
  • 5
  • My crystal ball says you should fix something at line 157. – JB Nizet Dec 04 '16 at 09:31
  • Questions like these need to include an [MCVE] or an [Short, Self Contained, Correct (Compilable), Example](http://sscce.org). Without that, it's like JB said, we'd need a crystal ball to help you. – TT. Dec 04 '16 at 09:39
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Dec 04 '16 at 10:20

1 Answers1

1

Use

JFrame.dispose()

on the second JFrame.

Also when using setDefaultCloseOperation() //this is what happens when you press x on window. avoid EXIT_ON_CLOSE and use DISPOSE_ON_CLOSE.

PS:Where is the code? :P

  • 1
    Thanks a lot bro! PS:I didn't think that the code was necessary.Well, I guess I learn't my lesson. – Akshay Dec 04 '16 at 10:49