问题
I have a JPanel with an vector image that the user can zoom and pan on. Overlaying this image is a (transparent) JComponent, which I allow the user to annotate the underlying image. This works great at full scale, but If I zoom in, using AffineTransform, the overlaying coordinates are affected also. So, If a user draws a box on the image the box is scaled also.
Any suggestions on how to decouple this behaviour? So that the JComponent is not affected by the JPanel's AffineTransform?
回答1:
Typically, you need both a forward and inverse transform to translate between the two co-ordinate systems. In this example, the scaling equations are explicit; in this alternate approach, a second AffineTransform is used.
来源:https://stackoverflow.com/questions/4292174/jcomponent-jpanel-zoom-pan-and-coordinates-question