完成创建自定义滚动条,问题是:
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
//How to know mouse direction - up or down?
}
});
也许有一些简单的方法,或者我必须手动完成?
完成创建自定义滚动条,问题是:
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
//How to know mouse direction - up or down?
}
});
也许有一些简单的方法,或者我必须手动完成?
您必须手动完成,但您需要 aMouseAdapter
而不是 aMouseMotionAdapter
来记录初始 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;
}
});