I need to calculate the new position of the viewport when zooming in to an image.
The UI is built up as follows:
You should be able to get the location of the mouse pointer using point.x and point.y - refer to the Point documentation here. Accouding to the MouseMotionEvent documentation here, the point.x and point.y are relative to the component under the mouse (the JScrollPane).
You can incorporate these values into your calculation. Is this kinda what you were looking for?