MouseMotionListener: mouse and trackpad give different results

58 views Asked by At

I'm using a MouseMotionListener to draw on a JComponent.

addMouseMotionListener(new MouseMotionAdapter() {
    public void mouseDragged(MouseEvent e) {
        System.out.println("DRAG ["+(i++)+"]");
        grid.handleMouseEvent(e);
    }
});

When I perform a mouse drag with my trackpad, I get the intended behavior. When I do the same thing with my actual mouse (USB), the drawing 'lags' quite a bit. I noticed that the source of the 'lag' comes from the mouseDragged method not getting invoked when I move my mouse too quickly. Why does this only happen with my mouse and not the trackpad?

Here is a (19s) GIF of two launches of the program. The first one shows the laggy drawing with the mouse. The second uses the trackpad and works as intended.

I understand that this may end up not being a problem with MouseMotionListener or even Java. If that is the case, I apologize. Maybe I could be redirected to another resource. Thanks!

0

There are 0 answers