开发者

Swing mouse drag identification problem?

开发者 https://www.devze.com 2023-03-25 03:19 出处:网络
How do I identify mouse dragged in downward di开发者_StackOverflow中文版rection? Suppose I dragged down, I need code such as this:

How do I identify mouse dragged in downward di开发者_StackOverflow中文版rection? Suppose I dragged down, I need code such as this:

int graphy = e.getY();
System.out.println("this is y axises " + graphy);
_graph._verticalScroll.setValue(graphy + _graph._headerWidth
    + _graph._verticalScroll.getValue());

What code should i put when mouse dragged down?


You can use a MouseAdapter and implement mouseDragged(MouseEvent e).

You have to check the coodrinates using e.getPoint() or e.getY() and compare with the previous event to get the direction.

You can detect if the mouse is dragged upwards or downwards with code similar to this:

if(e.getY() > previousY) {
  // drags downwards
} else if (e.getY() < preiousY) {
  // drags upwards
}
previousY = e.getY();
0

精彩评论

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

关注公众号