I have a JTable in which I want to call a function when a cell is double clicked and calls another function when the cell has a triple click.
When a triple-click cell, I do not want to call the double-click function.
Now I have (mgrdAlarm - JTable):
mgrdAlarm.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { System.out.println("getClickCount() = " + e.getClickCount()); if (e.getClickCount()==2) { doubleClick(); System.out.println("Completed : doubleClick()"); } if (e.getClickCount()==3) { tripleClick(); System.out.println("Completed : tripleClick()"); } } });
Double-clicking the console displays:
getClickCount() = 1 getClickCount() = 2 Completed : doubleClick()
When you click on the console three times, it displays:
getClickCount() = 1 getClickCount() = 2 Completed : doubleClick() getClickCount() = 3 Completed : tripleClick()
With a triple click, I want to show the console:
getClickCount() = 1 getClickCount() = 2 getClickCount() = 3 Completed : tripleClick()
Therefore, I do not want to call the doubleClick () function when the cell has a triple click, but I want to call the doubleClick () function when the cell is double-clicked.
[EDIT]
Like all answers, the solution seems to be to delay the double-click action and wait a certain time for the triple-click.
But as discussed here , which can lead to a different type of problem: Perhaps the user set the double-click time long enough that it could overlap with the timeout of my triple-click.
It is not a real disaster if my double-click action is executed before my triple-click action, but it creates some additional overhead and especially some additional data traffic that I would like to prevent.
As the only solution so far may lead to other problems that can be really worse than the original problem, I will leave it as it is now.