0

Is it possible to disable JFrame close operation?

EDIT.

frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(
        new WindowAdapter() {
            @Override
            public void windowClosing(final WindowEvent e) {

            }
        });

And this code doesn't solve the problem.

EDIT Is it possible to consume WindowClosing event?

Yegoshin Maxim
  • 870
  • 2
  • 20
  • 53
  • 1
    What is the problem if the `WINDOW_CLOSING` event is raised? It won't close the window - you will just get an event... – dacwe Mar 29 '12 at 15:01
  • -1 for not wanting the solutuin :-) Donothingonclose is exactly what you need to make the frame uncloseable. If that's not what you want, exlain what's wrong with an SSCCE – kleopatra Mar 29 '12 at 15:11
  • 1
    possible duplicate of [setDefaultCloseOperation not working in Swing](http://stackoverflow.com/questions/9924835/setdefaultcloseoperation-not-working-in-swing) – kleopatra Mar 29 '12 at 15:19
  • The topic at the link of "possible dublicate" has no answer. – Yegoshin Maxim Mar 29 '12 at 15:36
  • that snippet is not an sscce - and worksformealways so the error is somewhere else, maybe in your expectation, see @dacwe 's comment: certainly the frame isn't hidden and just as certainly the event must be and is fired (or how else would client code listen to it and optionally dispose or not?) – kleopatra Mar 29 '12 at 15:46
  • 2
    Unless you want to disable close during an operation in progress this does not make any sense from UI/UX stand point. Why would you provide a close button while you do not associate any action with it? You should look at `JWindow` or `setUndecorated(true);` – ring bearer Mar 29 '12 at 16:05
  • OK. Thank you all. Someone post an answer so I could accept it. – Yegoshin Maxim Mar 29 '12 at 16:10
  • Hopefully this [example](http://stackoverflow.com/q/9502882/1057230) might help you :-) – nIcE cOw Mar 29 '12 at 16:38

0 Answers0