关闭/退出子框架而不关闭父框架

时间:2014-01-06 12:32:52

标签: java swing jframe exit

我在另一帧中创建了第二帧。 我注意到,当我关闭第二帧时,第一帧也会关闭。

我怎么能避免这种情况? 我希望第一帧保持原样而不关闭。

我的第二帧代码是:

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

感谢

1 个答案:

答案 0 :(得分:5)

<强>解决

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

  • 已删除

     frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    
  • 添加以下

     setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);