问题
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