JDK-4449146 : mouseDragged event still fired while drag and drop
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2001-04-22
  • Updated: 2002-08-07
  • Resolved: 2002-08-07
Related Reports
Relates :  
Relates :  
Description

Name: boT120536			Date: 04/22/2001


java version "1.3.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

Hi all!

Here's my problem.
I have a component (a JList, but I don't think it depends on the component)
that has both a MouseMotionListener and a dragGestureRecognizer (don't ask me
why, I simply need to do that).
During the beginning of a drag and drop (not a simple mouseDragged event), the
normal behaviour is to get a few mouseDragged events, until the gesture
recognizer fires the drag and drop.
The fact is that when you drag and drop very quickly (leaving the component
very early with the mouse, before the drag and drop begins), the mouseDragged
events are continuously fired even after the drag and drop has begun/end!

  To demonstrate the problem, I have taken the drag and drop list example at this
address:
http://java.sun.com/docs/books/tutorial/dnd/sheetal.html
and modified the code of the DNDList constructor a bit :
  public DNDList() {
	
	dropTarget = new DropTarget (this, this);
	dragSource = new DragSource();
	dragSource.createDefaultDragGestureRecognizer( this,
DnDConstants.ACTION_MOVE, this);
	// Here's the mouse motion listener
	MouseMotionListener mouseMotionListener = new MouseMotionAdapter()
	{
		public void mouseDragged(MouseEvent e)
		{
			System.out.println(e.getPoint());
		}
	};
	addMouseMotionListener(mouseMotionListener);
}

As you can see, I simply added the mouse motion listener on the list.

Here is a normal output for a drag and drop :

java.awt.Point[x=89,y=6]
java.awt.Point[x=90,y=7]
java.awt.Point[x=91,y=7]
java.awt.Point[x=93,y=8]
1.dragGestureRecognized(dge)
java.awt.Point[x=96,y=8]
1. dragEnter(target)
1. dragOver(target)
1.dragEnter(source)
1. dragOver(target)
1.dragExit(source)
1. dragExit(target)
1.dragExit(source)
2. dragEnter(target)
2. dragOver(target)
1.dragEnter(source)
2. dragOver(target)
1.dragExit(source)
1.dragExit(source)
2. dragExit(target)
2. drop(DropTargetDropEvent)
1.dragExit(source)
1.dragDropEnd(dsde)

Now, if you drag from a location that is not very far from the bounds of the
list and you quickly drag outside of the list, then complete your drag and drop
operation, here's the output :
java.awt.Point[x=81,y=8]
java.awt.Point[x=82,y=8]
java.awt.Point[x=85,y=6]
1.dragGestureRecognized(dge)
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
2. dragEnter(target)
2. dragOver(target)
1.dragEnter(source)
2. dragOver(target)
1.dragExit(source)
java.awt.Point[x=89,y=-10]
2. dragOver(target)
1.dragExit(source)
2. dragOver(target)
1.dragExit(source)
java.awt.Point[x=89,y=-10]
2. dragOver(target)
1.dragExit(source)
2. dragOver(target)
1.dragExit(source)
2. dragExit(target)
2. drop(DropTargetDropEvent)
java.awt.Point[x=89,y=-10]
1.dragExit(source)
1.dragDropEnd(dsde)
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]
java.awt.Point[x=89,y=-10]

As you can see, the mouseDragged events are still fired even after the drop at
the same location (when the mouse was "lost" by the DND component).
I have reproduced this bug on many platforms (windows/jdk1.2.2, windows/jdk1.3,
linux/jdk1.3, Solaris/jdk1.2, AIX/jdk1.3).
You can download the complete source+classes for evaluating this bug as a zip
at:
http://jytou.free.fr/dndsun.zip
(Review ID: 120921) 
======================================================================

Comments
EVALUATION I'm not sure if this is an AWT mouse problem or a dnd problem. I'll let dnd take first crack at it. eric.hawkes@eng 2001-04-23 May have been recently fixed by Danila's mouse event changes. david.mendenhall@east 2001-04-26 Name: agR10216 Date: 08/07/2002 I reproduced the bug with the build 1.4.2-beta-b01. MouseDragged events are periodically delivered to any JComponent with the true autoscrolls property when the mouse is dragged outside of the component's bounds and mouse motion has paused (while the button continues to be held down). These events are synthetically generated by javax.swing.Autoscroller by means of javax.swing.Timer. If someone drags from a location that is not very far from the bounds of the component and quickly drags outside of the component, then the Timer starts before a DnD operation starts and generates mouseDragged events at regular intervals. Autoscroller expects to receive a mouseReleased event to stop the Timer, but the event does not come since the DnD operation starts. The Timer should be stopped when DnD operation starts. setAutoscrolls(false) could be called on the drag source JComponent when a DnD operation starts and after the drop autoscrolls could be restored, but such dependency on Swing is objectionable. Let Swing handle it. Closing the bug as will not fix. See the work around section for how to resolve the problem. ###@###.### 2002-08-07 ======================================================================
07-08-2002

WORK AROUND Name: boT120536 Date: 04/22/2001 I have no workaround for now. ====================================================================== Name: agR10216 Date: 08/07/2002 If you use a JComponent as a drag source, use Swing DnD support, or disable autoscrolls manually by call of JComponent.setAutoscrolls(false) before the start of a DnD operation (after the end of the DnD operation you could restore autoscrolls on your JComponent). ###@###.### 2002-08-07 ======================================================================
07-08-2002