通过使用MouseAdapter
收听,我成功地能够在我的应用中捕捉和处理垂直滚动事件。
以下是:
@Override
public void mouseWheelMoved(MouseWheelEvent e)
{
int n = e.getWheelRotation();
//scroll n times
}
我如何类似地处理水平滚动事件,例如在触控板上生成的事件?
提前致谢:)
答案 0 :(得分:0)
我找到了一个解决方案,据我的测试显示,该解决方案适用于Mac但不适用于Windows。水平滚动的解释方式与垂直滚动的解释方式相同,但按住了 Shift 。
因此覆盖以下侦听器方法可以完成这项工作:
@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.
}