void () { MouseAdapter mouseAdapter = new MouseAdapter() { boolean myIsEngaged; @Override public void mouseMoved(MouseEvent e) { Component focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (focusOwner == null) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(myList, true)); } if (myList.getSelectedIndices().length > 1) { return; } if (!myIsEngaged || UIUtil.isSelectionButtonDown(e) || focusOwner instanceof JRootPane) { myIsEngaged = true; return; } Point point = e.getPoint(); int index = myList.locationToIndex(point); myList.setSelectedIndex(index); Rectangle cellBounds = myList.getCellBounds(index, index); if (cellBounds != null && cellBounds.contains(point)) { UIUtil.setCursor(myList, Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); myHoverIndex = index; myList.repaint(cellBounds); } else { UIUtil.setCursor(myList, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); myHoverIndex = -1; myList.repaint(); } } @Override public void mouseExited(MouseEvent e) { myHoverIndex = -1; myList.repaint(); } }; myList.addMouseMotionListener(mouseAdapter); myList.addMouseListener(mouseAdapter); }