Domanda

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 :)

È stato utile?

Soluzione

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.
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top