I have a weird problem viewing a JPEG image by implementing Java Swing Scrollable interface.
My code allows me to draw a rectangle on top of the image using left-mouse button. Everything works ok if I don't touch the scroll bars.
But as soon as I scroll down, a rectangle gets drawn on a different location. Basically if I move the top-down scroll bar, the the image gets drawn with the wrong y-coordinate. Same behavior if scrolling left-right, the image gets drawn with the wrong x-coordinate. These x,y coordinates reporesent the upper-left Point(x,y) to start drawing Rectangle.
So after scrolling down and left-click on image to draw a rectangle the y-coordinate off. Below is an event I added to one of the panels that holds the image stuff.
public void mousePressed(MouseEvent m) {
if (SwingUtilities.isLeftMouseButton(m)) {
....
int y = m.getY(); //This y-coordinate is off whenever I scroll down the image.
...
}
}
Anyone has any clues onto what could be the problem? I mean I'm getting the y-coordinate from the MouseEvent, so I would expect it to have the correct value.
Thanks.