private static int getRow(JComponent component, Point point) {
    if (component instanceof JTable) {
      return ((JTable)component).rowAtPoint(point);
    }
    else if (component instanceof JList) {
      return ((JList<?>)component).locationToIndex(point);
    }
    else if (component instanceof JTree) {
      return ((JTree)component).getClosestRowForLocation(point.x, point.y);
    }
    else {
      throw new IllegalArgumentException("Unsupported component: " + component);
    }
  }
private static int getRow(JComponent component, Point point)