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?
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;
}
精彩评论