Java Swing two Action Listeners on one JCheckBox -


i have jcheckbox action listener implemented.

here, when it's checked, appears , when not checked, appearance disappears.

to implement this, should have 2 action listeners? how implement this?

you can use actionlistener , when action fired can check it's selected or not

final jcheckbox checkbox = new jcheckbox("my checkbox");  checkbox.addactionlistener(new actionlistener() {     @override     public void actionperformed(actionevent e)     {         // check if checkbox selected or not         if(checkbox.isselected()){             // here can fire event in checkbox mark selected             // , can display value want display         } else{             // checkbox not selected can fire event in checkbox not selected         }     } } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -