Question

I'm successfully able to catch and process vertical scrolling events in my application, by listening with my MouseAdapter.

Here's how:

@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
   int n = e.getWheelRotation();
   //scroll n times
}

How do I similarly process horizontal scroll events, such as those generated on a trackpad?

Thanks in advance :)

Was it helpful?

Solution

I've found a solution that, as far as my testing has revealed, works on Mac but not Windows. Horizontal scrolling is interpreted the same way as vertical scrolling, albeit with Shift held down.

Thus overriding the following listener method does the job:

@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
   int n = e.getWheelRotation();
   if(e.isShiftDown())
       //we've scrolled n times horizontally
   else
       //we've scrolled n times vertically.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top