简体   繁体   中英

CheckBox change of state when X Button is pressed

I have got this problem: I have JMenu, which consists of CheckBox. If that is checked (ItemEvent.selected), it opens a new JFrame, when unchecked (ItemEvent.Deselected) I dispose JFrame. Everything works OK. But when i push the "x" button on the top of the window, which is set as JFrame.DISPOSE_ON_CLOSE, I need to uncheck the checkbox in the JMenu. Right now it's like this: You check, then program opens new window, which you close with "x" button, then you open menu again and checkbox is checked, but window is already close. I tried to add some clickListener, but it!s getting destroyed with closing the frame. Any advice will be welcomed :)

As the question hasn't been put very well, its hard to determine exactly what your issue is. However... If you want to automatically uncheck the box when the window has closed, you could use a window listener on your JFrame.

frame.addWindowListener( new WindowAdapter() {
    @Override
    public void windowClosing(WindowEvent we) {
        //Uncheck the box
    }
} );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM