JFrame catch dispose event

I have a Java project.
I have a JFrame with a handler attached to it, so that

frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent evt) {
                this.setEnabled(true);

            }
        });

But on this frame, I also have a close button (to make it more convenient for the user), and the close button calls the frame removal method. Now, when I close the frame by clicking the small x button in the upper right corner, the WindowListener is called. But the event does not fire when the dispose method is called.
should I call some other method to close, so that the WindowListener fires, or perhaps implements another listener?

+3
source share
2 answers

( )

. , , "ExitAction" , , .

+3

, OP.

. windowClosed() , X myFrame.dispose().

JFrame myFrame = new JFrame();
myFrame.addWindowListener(new java.awt.event.WindowAdapter() {
    @Override
    public void windowClosed(java.awt.event.WindowEvent windowEvent) {
        // your code
    }
});

: https://alvinalexander.com/blog/post/jfc-swing/closing-your-java-swing-application-when-user-presses-close-but

0

Source: https://habr.com/ru/post/1774302/


All Articles