I hava a Java swing application that use a 'pan-able' JComponent to display large data. When the user move the mouse wheel, I listen to these events, and update the content of the JComponent from the scrolled amount.
I would like to have a different behavior depending on whether the user is
How could I detect that the user is using the mouse wheel vs the trackpad to generate the scroll event? I am relying in java 1.6 swing, si I cannot go to javaFX.
Story behind the question: I just wanted to add a cool inertia feel to the scrolling event when the user use the mouse wheel. But of course, on MacOSX, the trackpad has its own inertia stuff builtin. So I wanted to decide whether I should generate the inertial movement or not.
Java Swing is an old technology, it supports the traditional mouse wheel rotation events.
When you use the old wheel mouse, or wheel track-pad, it will read the rotation of the hardware wheel.
When you use a modern laser mouse, the mouse movement will be translated to rotation motion.
When you use a touch track-pad like the one in modern Mac laptops, the scroll gesture will be translated into rotation motion, single & double touch as left and right click (based on OS mouse-pad configuration).
You can use libraries to check the input devices in detail, in case your mouse or track-pad is connected to your computer through USB, you can try J-USB library.
As for internal hardware, you first have to identify the type of OS, and based on that you can get information on system and hardware in Java.
Finally, if your application interacts with a user, I suggest asking the user what type of mouse they're using, and store that in configuration file or something.
For MacOS you can get all the touchpad events in Java, I'd been searching myself for a while and just answered my own question. Leaving this here in case anyone else starts down the same rabbit hole
What replaces GestureUtilities in Java 9
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With