MouseDragged Flicker Image

Hi, I'm trying to drag a JPanel containing 2D Graphics and I have used a

mouseDragged listener. The image drags but the problem is is that it flickers inbetween two possible locations for some reason. Here is my code:

publicvoid mouseDragged(java.awt.event.MouseEvent mouseEvent){

((JPanel)mouseEvent.getSource()).setLocation(mouseEvent.getX(), mouseEvent.getY());

}

I printed out the coordinates and for some reason they jump from high coords down to lows like

x 119 y 66 down to x 18 y 13 , but i can't figure it out.

Does anyone know why this may be? thanks

Message was edited by:

kerryblue19

[779 byte] By [kerryblue19a] at [2007-11-27 10:33:38]
# 1

Can't explain 100% why it flicker but basically you have two different coordinate systems. The MouseEvent point is relative to the image, but when you set the location you set it relative to the parent panel.

You you need to move the image relative to its last position and the relative change in the mouseDragged event. Here is a better solution:

http://forum.java.sun.com/thread.jspa?forumID=57&threadID=599181

camickra at 2007-7-28 18:23:57 > top of Java-index,Desktop,Core GUI APIs...
# 2

I got it to work but now when I drag the panel it goes under other panels....like I have a card game lined up, with rows and columns of jpanels...ahh

Message was edited by:

kerryblue19

kerryblue19a at 2007-7-28 18:23:57 > top of Java-index,Desktop,Core GUI APIs...