Why does my application still run after closing main window?
java, swing
Solution
You should call the `setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);` in your JFrame.
Example code:
public static void main(String[] args) {
Runnable guiCreator = new Runnable() {
public void run() {
JFrame fenster = new JFrame("Hallo Welt mit Swing");
fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
fenster.setVisible(true);
}
};
SwingUtilities.invokeLater(guiCreator);
}
Problem
If I make a JFrame like this ``` public static void main(String[] args) { new JFrame().setVisible(true); } ``` then after closing the window the appication doesn't stop (I need to kill it). What is the proper way of showing application's main windows ? I'd also like to know a reason of a proposed solution. Thanks in advance.