void (ActionEvent e) { int[] viewRows = myTable.getSelectedRows(); int[] modelRows = new int[viewRows.length]; Map<T, S> selectedElements = new LinkedHashMap<>(viewRows.length); for (int i = 0; i < viewRows.length; i++) { int viewRow = viewRows[i]; int modelRow = myTable.convertRowIndexToModel(viewRow); T element = myTableModel.getElementAt(modelRow); selectedElements.put(element, myTableModel.getElementMarkState(element)); modelRows[i] = modelRow; } S nextState = myMarkStateDescriptor.getNextState(selectedElements); if (nextState != null) { myTableModel.setMarkState(modelRows, nextState); } }