2013-01-05 98 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); 
} 

之後,只需調用適當的方法。

相關問題