2013-01-05 101 views
0

我需要关闭我的应用程序当前窗口,而不关闭整个应用程序我的代码如下,以设置窗口可见,但它关闭所有窗口,当我点击时,当前打开的任何窗口右上角的红色十字按键关闭jframes当前窗口,而不是整个应用程序

private void lb_helpMouseClicked(java.awt.event.MouseEvent evt) {          
      new Reports().setVisible(true); 
    }   
private void lb_certMouseClicked(java.awt.event.MouseEvent evt) {          
     new ChooseCert().setVisible(true); 
    } 
private void lb_reportMouseClicked(java.awt.event.MouseEvent evt) { 
     new Reports().setVisible(true); 
    } 
+0

Try frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); –

+1

听起来像EXIT_ON_CLOSE是问题,而不是解决方案。将任何将默认关闭操作设置为EXIT_ON_CLOSE的行更改为使用DISPOSE_ON_CLOSE。 – VGR

回答

0
public void closeWindow() { 
    WindowEvent wev = new WindowEvent(this, WindowEvent.WINDOW_CLOSING); 
    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev); 

    setVisible(false); 
    dispose(); 
} 

public void closeApplication() { 
    System.exit(0); 
} 

之后,只需调用适当的方法。

相关问题