I have a simple mouse manager class: https://i.stack.imgur.com/EIcEt.jpg

Whenever any of the mouse buttons are pressed the mouse position does not update when calling getMouseX() or getMouseY() on the mouse manager object via a basic handler that gets passed everywhere.

Is the problem in my implementation or is it a bug in general?


1 Answer 1


The problem is with your implementation.

Change your button handling code to something like :

if (e.getButton() == MouseEvent.Button1) {
    leftpressed = true;
    mouseX = e.getX();
    mouseY = e.getY();

Basically you want to update the stored mouse position on all mouse events.

  • \$\begingroup\$ Thanks! Works perfectly! Just needed to update the mouse position on mouseDragged(MouseEvent e) function in the mouse manager class. \$\endgroup\$
    – Kerdo
    Feb 28, 2018 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .