2014-01-06 82 views
2

我在另一个框架中创建了第二个框架。 我注意到当我关闭第二帧时,第一帧也关闭了。关闭/退出没有关闭父框架的子框架

我该如何避免这种情况? 我希望第一帧保持原样并且不关闭。

我的第二帧代码:

JFrame.setDefaultLookAndFeelDecorated(true);  
frame = new JFrame(); 
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); //when it closes the first frame closes too 

感谢

+0

可能的复制[而不关闭另一个关闭一个的JFrame?](http://stackoverflow.com/questions/ 1944446/close-one-jframe-without-closing-another) – Blasanka

回答

5

解决

我读了以下的答案Close one JFrame without closing another?,我找到了答案

  • 除去

    frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE); 
    
  • 和我加入以下的

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
    
+4

一个复本应该只有一个JFrame。对于子窗口,您应该使用JDialog。参见:http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice – camickr