当mouseDoubleClick出现时停止mouseDown事件

时间:2010-05-08 21:20:52

标签: java swt

我有一个监听mouseDown和mouseDoubleClick事件的控件。但是当mouseDoubleClick出现时,我不需要处理mouseDown事件。 (现在,当doubleClick发生时,两个事件都被触发) 如何在mouseDoubleClick发生时停止处理mouseDown事件?

1 个答案:

答案 0 :(得分:2)

如果我理解得很好,你可以这样做:

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;
}

所以我不知道这是否与SWT相关,但这是使用AWT MouseListener。


我搜索了一下,所以我认为这适用于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;
}