Swing鼠标拖动识别问题?
如何识别鼠标向下拖动?假设我向下拖动,我需要这样的代码:
int graphy = e.getY();
System.out.println("this is y axises " + graphy);
_graph._verticalScroll.setValue(graphy + _graph._headerWidth
+ _graph._verticalScroll.getValue());
当鼠标向下拖动时我应该放置什么代码?
How do I identify mouse dragged in downward direction? 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 MouseAdapter 并实现
mouseDragged(MouseEvent e)
。您必须使用
e.getPoint()
或e.getY()
检查坐标,并与之前的事件进行比较以获得方向。您可以使用类似以下的代码来检测鼠标是否向上或向下拖动:
You can use a MouseAdapter and implement
mouseDragged(MouseEvent e)
.You have to check the coodrinates using
e.getPoint()
ore.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: