Reputation: 51
Is there a way to set a JToggleButton as selected or deselected without actually firing the itemevent linked to it. I have a jtogglebutton that I want fired in certain instances, but for ui purposes I would like to occasionally change it's selected state without actually firing the button. Any input would be appreciated, thanks.
Upvotes: 1
Views: 77
Reputation: 5415
Two different approaches:
1) Remove the listener, then set the state of the toggle, then add the listener back
2) Wrap the logic of your listener code with a boolean flag, let's call it toggleAdjusting
, to only fire if false. Then elsewhere, when you want to set the state of the toggle without the listener code running, simply set the flag to true, adjust the toggle, then set the flag back to false.
Upvotes: 2