void (MouseEvent e) { if (e.getID() == MouseEvent.MOUSE_MOVED) { boolean onLink = isOnLink(e.getX()); boolean needRepaint = myMouseHover != onLink; myMouseHover = onLink; setCursor(myMouseHover ? Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) : null); if (needRepaint) { repaint(); } } super.processMouseMotionEvent(e); }