3

I need to implement zoom for a JDesktopPane contained in a JScrollPane. I have had prior success zooming by overriding the paintComponent(...) method and calling scale(double,double).

This is not working properly: the JInternalFrame's and JPanel's scale as intended, but the MouseListener's for the JLabel's and such register at the pre-scaled locations. What can I do? Thank you for reading.

farm ostrich
  • 5,881
  • 14
  • 55
  • 81
  • can't you scale the mouse coordinate too? – Heisenbug Aug 21 '11 at 21:56
  • For a jlabel with a mouseListener, the mouseEntered(), mouseExited(),... all of its methods registers at the unscaled location. Doing some mouse coordinate scaling like mouseEvent.getX()/scaleFactor won't fix that problem. – farm ostrich Aug 21 '11 at 23:03

1 Answers1

3

ScaledPanel shows how to scale mouse coordinates using explicit transformation methods: scaleX, scaleY, unScaleX and unScaleY. Alternatively, you can use an inverse transformation, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • I already knew how to scale mouse coordintes, that isn't the problem. but thanks anyways. – farm ostrich Aug 22 '11 at 01:39
  • 1
    Ah, I see now: you're going to watch `mouseMoved()` and scale the coordinates in order to determine your own `mouseEntered()`. – trashgod Aug 22 '11 at 01:52
  • There's a lot of moving pieces on screen, I was hoping I wouldn't have to resort to 'collision detection'. But ok, there's probably no better way. – farm ostrich Aug 22 '11 at 12:17