2

I have an application that creates a new window (let's call it Cuprins) when a button of the same name is pressed. The problem I have is that when I close the new window, it also closes the main one. Is there anyway to make the main window not close when closing the Cuprins window?

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
Casteurr
  • 946
  • 1
  • 15
  • 35
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) (But see also `JFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)` as seen in [this answer](http://stackoverflow.com/questions/7143287/how-to-best-position-swing-guis/7143398#7143398) for the immediate 'fix'.) – Andrew Thompson Dec 31 '12 at 15:19

3 Answers3

5

Check what's the default close operation. Set it to "dispose on close" or "do nothing on close"

Andrew Thompson
  • 166,747
  • 40
  • 210
  • 420
StanislavL
  • 56,113
  • 9
  • 64
  • 93
1

The newly opened window should use dispose on close to dispose the frame, or setVisible(false) to hide it temporarily.

Xiaoerge
  • 101
  • 1
  • 1
0

Just use this line while you creating child window.

myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

Usage example :

AddLeagues addLeague = new AddLeagues(); //Child View
addLeague.setVisible(true);
myFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Abhijith
  • 2,744
  • 1
  • 27
  • 35