tags:

views:

69

answers:

1

I have a control which is listened for both mouseDown and mouseDoubleClick events. However when mouseDoubleClick occure, I don't need mouseDown event to be handled. (Now both events fired when doubleClick happens) How can I stop handling mouseDown event when mouseDoubleClick occured?

+2  A: 

If I understand well, you can do something like:

private boolean doubleClicked = false;

public void mouseClicked(MouseEvent evt)
{
     if (evt.getClickCount() == 2)
     {
         doubleClicked = true;
         // Handle here your double click
     }
}

public void mousePressed(MouseEvent evt)
{
     if (doubleClicked)
     {
         return;
     }
     // Handle here your mouse down
}

public void mouseReleased(MouseEvent evt)
{
     doubleClicked = false;
}

So I don't know if this is relevant with SWT or not, but this is with AWT MouseListener.


I searched a bit, so I think this can work for SWT:

// Place this in your class body, otherwise you have to make it final
// and that is not what we want.
private boolean doubleClicked = false;

// Mouse Double Click
public void handleEvent(Event evt)
{
     doubleClicked = true;
     // Handle here your double click
}

// Mouse Down
public void handleEvent(Event evt)
{
     if (doubleClicked)
     {
         return;
     }
     // Handle here your mouse down
}

// Mouse Up
public void handleEvent(Event evt)
{
     doubleClicked = false;
}
Martijn Courteaux
this could work, but mouseDown event triggers first
kilonet