Intercept checkbox action

Is it possible to intercept a user checking a checkbox so I can do some magic before deciding if the checkbox should be checked or not?

If I write a script on actionPerformed, it still checks the box no matter how I try and prevent it.

Thanks!

Would you be able to check conditions beforehand and toggle the enable of the checkbox accordingly?

Quick video on accomplishing through scripting (a la original post).