JScrollPane - Zoom relative to mouse position

前端 未结 2 405
小蘑菇
小蘑菇 2020-12-14 04:23

I need to calculate the new position of the viewport when zooming in to an image.

The UI is built up as follows:

  • ImagePanel draws the image
  • Im
2条回答
  •  萌比男神i
    2020-12-14 05:11

    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?

提交回复
热议问题