@Override protected void setSelectedIndex(int index, boolean incremental) { int majorIndex, minorIndex; JTable table = ((JTable) _component); if (isColumnSelectionAllowed(table)) { minorIndex = index; majorIndex = getMainIndex(); addTableSelection(table, majorIndex, minorIndex, incremental); } else if (isRowSelectionAllowed(table)) { majorIndex = index; minorIndex = table.convertColumnIndexToView(getMainIndex()); addTableSelection(table, majorIndex, minorIndex, incremental); } else { // cell selection allowed int columnCount = table.getColumnCount(); if (columnCount == 0) { return; } majorIndex = index / columnCount; minorIndex = index % columnCount; addTableSelection(table, majorIndex, minorIndex, incremental); } }
@Override protected Object getElementAt(int index) { JTable table = (JTable) _component; if (isColumnSelectionAllowed(table)) { // column selection mode return getValueAt(table, getMainIndex(), index); } else if (isRowSelectionAllowed(table)) { // row selection mode return getValueAt(table, index, table.convertColumnIndexToView(getMainIndex())); } else if (isSearchSelectedRows()) { // search on multi columns int columnIndex = index % table.getColumnCount(); int modelIndex = table.convertColumnIndexToModel(columnIndex); boolean doNotSearch = true; for (int i : getSearchColumnIndices()) { if (i == modelIndex) { doNotSearch = false; } } if (doNotSearch) { return null; } int rowIndex = index / table.getColumnCount(); return getValueAt(table, rowIndex, columnIndex); } else { // cell selection allowed int columnIndex = index % table.getColumnCount(); int rowIndex = index / table.getColumnCount(); return getValueAt(table, rowIndex, columnIndex); } }