What Is It

The ClickSensitivityControl class helps simulate MOUSE_CLICKED events even if the mouse moves a few pixels.

By default Java only fires MOUSE_CLICKED events after receiving a MOUSE_PRESSED and a MOUSE_RELEASED at exactly the same (x,y) location.

How To Use It

All you need to call is: ClickSensitivityControl.install().

How It Works

The ClickSensitivityControl object uses a global AWTEventListener to listen for mouse activity. After receiving a MOUSE_RELEASED event: it checks to see if the mouse stayed within a certain range of pixels, and if so it may fire its own MOUSE_CLICKED event.

At any point if the user strays outside of the allotted range: we abort the potential MOUSE_CLICKED event. Also if someday Java changes its behavior: this class should detect the other MOUSE_CLICKED event and not fire a redundant event.

Discussion

Over the years we found the default Java behavior became problematic for a minority of our users.

You can think of this as an accessibility feature: if someone has minor hand tremors, then its harder for them to keep their mouse perfectly still. (Actually where this first came up for us was with small children who lacked the motor control most adult users have.)

Also this is useful for remote mice, or touchpads. In my opinion Java's default behavior works best with a traditional mouse, but with more abstract pointer devices: it's not always a safe bet that the mouse coordinates won't move at least a little bit when the user clicks.

It's worth noting that these concerns do not affect buttons. JButtons do not rely on MOUSE_CLICKED events. They have their own complex interaction model involving arming buttons. The ClickSensitivityControl only affects logic listening for MOUSE_CLICKED events, such as the BasicTreeUI.