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);
}
});
}
}