JDK-6403381 : REGRESSION: MouseDragged and DragGestureRecognized events' order is swapped.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-03-24
  • Updated: 2010-04-03
  • Resolved: 2006-03-27
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REGRESSION :
Create component. Add MouseMotionListener and DragGestureListener to it.
Drag mouse across the component.

REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class TestApp {
	private final JFrame frame = new JFrame();
	private final JPanel panel = new JPanel();

	public static void main(String[] args) {
		new TestApp().start();
	}

	public void start() {
		frame.getContentPane().add(panel);
		panel.setSize(100, 100);
		panel.addMouseMotionListener(new MyMouseListener());
		frame.addWindowListener(new WindowListener() {
			public void windowActivated(WindowEvent e) {}
			public void windowClosed(WindowEvent e) {}
			public void windowClosing(WindowEvent e) {
				frame.dispose();
				System.exit(0);
			}
			public void windowDeactivated(WindowEvent e) {}
			public void windowDeiconified(WindowEvent e) {}
			public void windowIconified(WindowEvent e) {}
			public void windowOpened(WindowEvent e) {}
		});
		frame.show();
	}

	private class MyMouseListener implements MouseMotionListener {
		public MyMouseListener() {
			final DragSource dragSource = DragSource.getDefaultDragSource();
			DragGestureListener gesture = new DragGestureListener() {
				public void dragGestureRecognized(DragGestureEvent dge) {
					System.out.println("dragGestureRecognized");
				}
			};
			dragSource.createDefaultDragGestureRecognizer(panel,
					DnDConstants.ACTION_COPY_OR_MOVE, gesture);

		}
		public void mouseDragged(MouseEvent e) {
			System.out.println("mouseDragged");
		}
		public void mouseMoved(MouseEvent e) {}
	}
}


RELEASE LAST WORKED:
5.0

RELEASE TEST FAILS:
mustang-b72

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
MouseDragged is the first fired event. DragGestureRecognized is fired later.
ACTUAL -
DragGestureRecognized is the first fired event, MouseDragged is the second one.

Comments
EVALUATION In essence, a drag gesture recognizer is a MouseListener and MouseMotionListener simultaneously. The drag gesture recognizer receives MouseDragged events on a par with any other MouseMotionListener. The drag gesture recognizer fires a DragGestureEvent in accord with the spec for the class java.awt.dnd.MouseDragGestureRecognizer. Using the test case, the first MouseDragged event results in firing the DragGestureEvent. Then the same MouseDragged event is passed to MyMouseListener.mouseDragged(). Mouse dragged events are not sent till the mouse is dragged out of a certain rectangle. It's a result of the intentional change 5039416. So this issue is not a bug.
27-03-2006