In my Java Swing app, I have a JList, and when I double click on an item in the list, it always does click count == 1 things first then do things in click count == 2, why ?
list.addMouseListener(new MouseAdapter()
{
public void mouseClicked(MouseEvent e)
{
if (SwingUtilities.isLeftMouseButton(e))
{
if (e.getClickCount()==1) Out("Left-ClickCount()==1");
else if (e.getClickCount()==2) Out("Left-ClickCount()==2");
}
else if (SwingUtilities.isRightMouseButton(e))
{
if (e.getClickCount()==2) Out("Right-ClickCount()==2");
else if (e.getClickCount()==1) Out("Right-ClickCount()==1");
}
}
});
No matter how fast I click, I intentionally put "if (e.getClickCount()==2)" before "else if (e.getClickCount()==1)", it still catches ClickCount==1 first ? Why ? How to fix it ?
OK, after some Goggling and my own enhancement, here is the code that works to my original expectations :