MouseListener for JPanel missing mouseClicked events
Per http://download.oracle.com/javase/tutorial/uiswing/events/mouselistener.html:
"You will see a mouse-released event. If you did not move the mouse, a mouse-clicked event will follow."
I just had this problem. If you move the mouse AT ALL, a clicked event won't happen. I truly have no idea what good mouseClicked is given this knowledge. I fixed it by using mouseReleased and checking if the mouse was within the object:
public void mouseReleased(MouseEvent e) {
if(objectWithListener.contains(e.getPoint())){
doClickAction();
}
}
I think I found the problem here. I was getting intermediate mouseDragged events between the mousePress and mouseRelease. mouseMoved didn't seem to cause the problem, but mouseDragged did.
I'm not sure of the right solution now, but at least now I can explain what is happening.
Cheers
-Bill