private static int getRowCount(JComponent component) {
    if (component instanceof JTable) {
      return ((JTable)component).getRowCount();
    }
    else if (component instanceof JList) {
      return ((JList)component).getModel().getSize();
    }
    else if (component instanceof JTree) {
      return ((JTree)component).getRowCount();
    }
    else {
      throw new IllegalArgumentException("Unsupported component: " + component);
    }
  }
private static int getRowCount(JComponent component)