void (@NotNull Component c, boolean allowDragWhileClicking) { myListener = new MouseAdapter() { private Point pressPoint; private Point lastClickPoint; private long lastTimeClicked = -1; private int clickCount = 0; @Override public void mousePressed(MouseEvent e) { final Point point = e.getPoint(); SwingUtilities.convertPointToScreen(point, e.getComponent()); if (Math.abs(lastTimeClicked - e.getWhen()) > UIUtil.getMultiClickInterval() || lastClickPoint != null && !isWithinEps(lastClickPoint, point)) { clickCount = 0; lastClickPoint = null; } clickCount++; lastTimeClicked = e.getWhen(); if (!e.isPopupTrigger()) { pressPoint = point; } } @Override public void mouseReleased(MouseEvent e) { Point releasedAt = e.getPoint(); SwingUtilities.convertPointToScreen(releasedAt, e.getComponent()); Point clickedAt = pressPoint; lastClickPoint = clickedAt; pressPoint = null; if (e.isConsumed() || clickedAt == null || e.isPopupTrigger() || !e.getComponent().contains(e.getPoint())) { return; } if ((allowDragWhileClicking || isWithinEps(releasedAt, clickedAt)) && onClick(e, clickCount)) { e.consume(); } } @Override public void mouseClicked(MouseEvent e) { if (e instanceof SyntheticClickEvent && !e.isConsumed() && onClick(e, e.getClickCount())) { e.consume(); } } }; c.addMouseListener(myListener); }