aps
aps

Reputation: 2472

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 information, I have a JPanel inside a JScrollPane. I will use mouse wheel motion to zoom in or out.

Upvotes: 4

Views: 4127

Answers (2)

Coderman69
Coderman69

Reputation: 67

event.getWheelRotation()

-1 = Up

1 = Down

Upvotes: 2

Coeffect
Coeffect

Reputation: 8866

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.

Upvotes: 5

Related Questions