开发者

Detecting which way mouse is scrolled

There is only one method in the MouseWheelListener interface. I need to do different things depending on whether the mouse is scrolled up or down. How to achieve such a thing? Just for inform开发者_开发问答ation, I have a JPanel inside a JScrollPane. I will use mouse wheel motion to zoom in or out.


The mouseWheelMoved method takes a MouseWheelEvent parameter. There are fields in that parameter that you can use to determine the direction of the scrolling (see MouseWheelEvent). So once you know which direction the wheel moved in, you can decide what action to perform.


event.getWheelRotation()

-1 = Up

1 = Down

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜