How to pan an image using your mouse in Java Swing
问题 I am creating a Java app that will allow users to view images and to pan the image using their mouse. To implement the panning of the image I use a combination of mouseClicked and mouseDragged events using JViewports. The bulk of the code is in the mouseDragged method public void mouseDragged(MouseEvent e, WindowWrapper w) { final JViewport vp = someFieldViewPort; //Getting the point that the mouse is dragged to to Point cp = e.getPoint(); final Point vPoint = vp.getViewPosition(); //I found