1

While setting up a dynamic component in my program, I noticed that there was some flickering whenever the component (a JPanel) was relocated. So, I printed the mouse position at each drag event using:

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

And it came out with some interesting results. With normal-speed drag from left to right, I got the following output in the console:

49
47
...
55
53
58
56
61
59
64
62
67
65
70
65
73
68
76
71
79
74
...
97
92
100
95
103
95
106

You'll notice the numbers fluctuate up then down as the tracking proceeds. I've fixed this before by throwing some math at it, but it now I'm wondering why and how I can make it work normally. Are certain MouseEvents processed before their event predecessors?

Kyle
  • 151
  • 1
  • 2
  • 14
  • I think mouse speed will affect this result, as if you move the mouse slowly, you see the increasing will be one each time. – Azad Aug 10 '13 at 18:57
  • Au contraire, I get the same results no matter what speed I move the mouse at. Are you running a successful model of this? – Kyle Aug 10 '13 at 18:59
  • Yes, the result was like what I said. – Azad Aug 10 '13 at 19:07
  • For my model numbers are also quite sequential. I suppose something is wrong with the mouse you're using or something in your app is generating additional events. – Jk1 Aug 10 '13 at 19:08
  • Interesting. I am using a gaming mouse with custom dpi settings. Could that be it? – Kyle Aug 10 '13 at 20:17

0 Answers0