完成创建自定义滚动条,问题是:
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
//How to know mouse direction - up or down?
}
});
也许有一些简单的方法,或者我必须手动完成?
答案 0 :(得分:4)
您必须手动执行此操作,但您需要MouseAdapter
而不是MouseMotionAdapter
来记录初始Y坐标。
addMouseMotionListener(new MouseAdapter() {
int previousY;
@Override
public void mousePressed(MouseEvent e) {
previousY = e.getY();
}
@Override
public void mouseDragged(MouseEvent e) {
int y = e.getY();
if (y < previousY) {
System.out.println("UP");
} else if (y > previousY) {
System.out.println("DOWN");
}
previousY = y;
}
});