문제

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

도움이 되었습니까?

해결책

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.
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top