Added a listener for the window. When closing using JOFreePane, it is asked: Does the user want to close the window? If yes, then the window closes; if not, nothing happens. But this is how it should work. In fact, no matter what (yes / no) the window closes anyway. What is the problem?

frame.addWindowListener(new WindowListener() { public void windowClosing(WindowEvent event) { Object[] options = { "Да", "Нет" }; int n = JOptionPane.showOptionDialog(event.getWindow(), "Закрыть окно?", "Подтверждение", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (n == JOptionPane.YES_OPTION) { event.getWindow().dispose(); } } @Override public void windowActivated(WindowEvent e) {} public void windowClosed(WindowEvent e) {} public void windowDeactivated(WindowEvent e) {} public void windowDeiconified(WindowEvent e) {} public void windowIconified(WindowEvent e) {} public void windowOpened(WindowEvent e) {} }); 

    1 answer 1

     setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);