JDK-6411407 : REGRESSION: Odd threshould for initial mouseDragged event
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-04-11
  • Updated: 2007-10-16
  • Resolved: 2006-04-11
Related Reports
Duplicate :  
Description
Compile and run the below test.
Press somewhere in the frame and the console will show:
    "Pressed at " + the x position you pressed at.
Now try to drag one pixel to the right and nothing happens.
Now try to drag a second pixel to the right and nothing happens.
Only after dragging three pixels do you get a mouse dragged event and a message:
    "You moved 3 to..."
At this point, you can now drag by single pixels in any direction.

This odd threshold of 3 happens on the initial drag after every press. This is a regression since 1.5.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MouseProbTest extends JFrame {

    Point p;

    public MouseProbTest() {
        super("MouseProbTest");

        getContentPane().addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent me) {
                p = me.getPoint();
                System.out.println("Pressed at " + (int)me.getX());
            }
        });

        getContentPane().addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent me) {
                int diff = (int)(me.getX() - p.getX());
                System.out.println("You moved " + diff + " to " + (int)me.getX());
            }
        });
    }

    private static void createAndShowGUI(String[] args) {
        MouseProbTest test = new MouseProbTest();
        test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        test.setSize(400, 400);
        test.setLocationRelativeTo(null);
        test.setVisible(true);
    }
    
    public static void main(final String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI(args);
            }
        });
    }
}

Comments
EVALUATION I tried the test with the patched with 6404008 workspace and it now behaves like JDK5.0b64. Believe it's a duplicate of that one.
11-04-2006