I have a problem while trying to drag and drop JPanel. If I implement it exclusively in MouseDragged as:
public void mouseDragged(MouseEvent me) {
me.getSource().setLocation(me.getX(), me.getY());
}
I get the strange effect of a moving object bouncing between two positions all the time (generating more “draggable” events). If I do it as described in this post , but with:
public void mouseDragged(MouseEvent me) {
if (draggedElement == null)
return;
me.translatePoint(this.draggedXAdjust, this.draggedYAdjust);
draggedElement.setLocation(me.getX(), me.getY());
}
I get the effect of an element that bounces a lot less, but it is still visible, and the element moves only 1/2 the path that the mouse pointer makes. Why is this happening / how can I fix this situation?
source
share