我已经创建了一个图像查看器,可以在鼠标释放时放大和缩小鼠标。当鼠标按下时,您可以拖动图像:
public void dragOnMouseMove( MouseEvent event ) {
if( zoomedIn ) {
if( mouseStartX != null && mouseStartY != null ) {
double x = this.getTranslateX() - (mouseStartX - event.getX());
double y = this.getTranslateY() - (mouseStartY - event.getY());
LOG.debug( "moving picture to: " + x + "," + y );
this.setTranslateX( x );
this.setTranslateY( y );
}
mouseStartX = event.getX();
mouseStartY = event.getY();
}
}这必然会拖拽事件。问题是:当鼠标到达屏幕边界时,拖动停止,因为坐标没有更多的变化。有没有一种方法可以独立于光标位置来检测鼠标移动?
发布于 2016-05-26 05:15:52
如果我很理解你的意思,找一个MouseInfo.getPointerInfo().getLocation()可能会有帮助。它返回一个与当前鼠标位置对应的Point对象。
https://stackoverflow.com/questions/37446541
复制相似问题