dispose() is not the same as setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

非 Y 不嫁゛ 提交于 2020-01-05 03:32:21

问题


I noticed that if setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) is set, closing the frame will end its Process in Task Manager, but if i implement WindowListener and manually dispose() the frame, Process will remain... probably because in new Runnable() i have something like this:

new Runnable() {
    void run() {
    Jsch tunnel=new Jsch();
    JFrame frame=new JFrame();
    frame.addWindowListener(new WindowListener() { frame.dispose(); } ); // imagine that this is legal 
    frame.setVisible(true);
    }
}

Anyone can tell me, how to manually end process created by some application?


回答1:


From the API docs.

  • EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.

So to force an exit call System.exit(0);.

When all top level windows are disposed, the AWT Event Dispatch Thread can be shut down (a new one can be create if needed). When there are no non-daemon threads left in the process, it will exit.



来源:https://stackoverflow.com/questions/17266202/dispose-is-not-the-same-as-setdefaultcloseoperationjframe-exit-on-close

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!