void (final @NotNull JTable table) { ListSelectionListener listener = new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!shouldUpdateHint()) return; int selected = ((ListSelectionModel)e.getSource()).getLeadSelectionIndex(); int rowCount = table.getRowCount(); if (selected == -1 || rowCount == 0) return; PsiElement element = getPsiElementForHint(table.getValueAt(Math.min(selected, rowCount - 1), 0)); if (element != null && element.isValid()) { updateHint(element); } } }; table.getSelectionModel().addListSelectionListener(listener); table.getColumnModel().getSelectionModel().addListSelectionListener(listener); }