javaswingmouseclick-eventmouse-listenersawt-eventqueue

Can't filter MouseEvent.MOUSE_CLICKED in AWT EventQueue


I need in my own AWT EventQueue filtering mouse double clicks, so I do:

public class AppEventQueue extends EventQueue
{
@Override
protected void dispatchEvent(AWTEvent event)
{
    super.dispatchEvent(event);
    if(event instanceof MouseEvent)
    {
        MouseEvent mouseEvent = (MouseEvent) event;
        if(mouseEvent.getModifiers() == MouseEvent.MOUSE_CLICKED)
        {
            //do something
        }
    }
}
}

Problem I have is that it looks that click with mouse is generating int value 16, MouseEvent.MOUSE_CLICKED has value 500. Am I missing something?


Solution

  • you want to check the id:

    if (mouseEvent.getID() == MouseEvent.MOUSE_CLICKED {
    
    }