Java - how do I prevent WindowClosing from actually closing the window
I seem to have the reverse problem to most people. I have the following pretty standard code to see if the user wants to do some saves before closing the window: frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ev) { boolean close = true; // check some files, asking if the user wants to save // YES and NO handle OK, but if the user hits Cancel on any file, // I want to abort the close process // So if any of them hit Cancel, I set "close" to false if (close) { frame.dispose(); System.exit(0)