void (JComponent component, int row) { if (component instanceof JTable) { ((JTable)component).getSelectionModel().setSelectionInterval(row, row); } else if (component instanceof JList) { ((JList<?>)component).setSelectedIndex(row); } else if (component instanceof JTree) { ((JTree)component).setSelectionRow(row); } else { throw new IllegalArgumentException("Unsupported component: " + component); } }