boolean (@NotNull JTable table, @NotNull ItemRemovable itemRemovable, @Nullable ItemChecker applyable) { if (table.isEditing()) { table.getCellEditor().stopCellEditing(); } ListSelectionModel selectionModel = table.getSelectionModel(); int minSelectionIndex = selectionModel.getMinSelectionIndex(); int maxSelectionIndex = selectionModel.getMaxSelectionIndex(); if (minSelectionIndex == -1 || maxSelectionIndex == -1) { return false; } TableModel model = table.getModel(); boolean removed = false; for (int index = maxSelectionIndex; index >= 0; index--) { int modelIndex = table.convertRowIndexToModel(index); if (selectionModel.isSelectedIndex(index) && (applyable == null || applyable.isOperationApplyable(model, modelIndex))) { itemRemovable.removeRow(modelIndex); removed = true; } } if (!removed) { return false; } int count = model.getRowCount(); if (count == 0) { table.clearSelection(); } else if (selectionModel.getMinSelectionIndex() == -1) { if (minSelectionIndex >= model.getRowCount()) { selectionModel.setSelectionInterval(model.getRowCount() - 1, model.getRowCount() - 1); } else { selectionModel.setSelectionInterval(minSelectionIndex, minSelectionIndex); } } return true; }