int (@NotNull JTable table) { if (table.isEditing()){ table.getCellEditor().stopCellEditing(); } TableModel model = table.getModel(); ListSelectionModel selectionModel = table.getSelectionModel(); int counter = 0; for(int row = 0; row < model.getRowCount(); row++){ if (selectionModel.isSelectedIndex(row)) { counter++; for (int column = 0; column < model.getColumnCount(); column++) { Object temp = model.getValueAt(row, column); model.setValueAt(model.getValueAt(row - 1, column), row, column); model.setValueAt(temp, row - 1, column); } selectionModel.removeSelectionInterval(row, row); selectionModel.addSelectionInterval(row - 1, row - 1); } } Rectangle cellRect = table.getCellRect(selectionModel.getMinSelectionIndex(), 0, true); table.scrollRectToVisible(cellRect); table.repaint(); return counter; }