void (final @Nullable ElementProducer<?> producer) { final JTable table = myTable; final EditableModel tableModel = (EditableModel)table.getModel(); myAddAction = new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { TableUtil.stopEditing(table); final int rowCount = table.getRowCount(); if (tableModel instanceof ListTableModel && producer != null) { //noinspection unchecked ((ListTableModel)tableModel).addRow(producer.createElement()); } else { tableModel.addRow(); } if (rowCount == table.getRowCount()) return; final int index = table.getModel().getRowCount() - 1; table.setRowSelectionInterval(index, index); table.setColumnSelectionInterval(0, 0); table.editCellAt(index, 0); TableUtil.updateScroller(table); //noinspection SSBasedInspection SwingUtilities.invokeLater(() -> { final Component editorComponent = table.getEditorComponent(); if (editorComponent != null) { final Rectangle bounds = editorComponent.getBounds(); table.scrollRectToVisible(bounds); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(editorComponent, true)); } }); } }; myRemoveAction = new AnActionButtonRunnable() { @Override public void run(AnActionButton button) { if (TableUtil.doRemoveSelectedItems(table, tableModel, null)) { updateButtons(); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(table, true)); TableUtil.updateScroller(table); } } }; class MoveRunnable implements AnActionButtonRunnable { final int delta; MoveRunnable(int delta) { this.delta = delta; } @Override public void run(AnActionButton button) { int row = table.getEditingRow(); int col = table.getEditingColumn(); int rowCount = table.getModel().getRowCount(); TableUtil.stopEditing(table); int[] idx = table.getSelectedRows(); Arrays.sort(idx); if (delta > 0) { idx = ArrayUtil.reverseArray(idx); } if (idx.length == 0) return; if (idx[0] + delta < 0) return; if (idx[idx.length - 1] + delta > rowCount) return; for (int i = 0; i < idx.length; i++) { tableModel.exchangeRows(idx[i], idx[i] + delta); idx[i] += delta; } TableUtil.selectRows(table, idx); TableUtil.scrollSelectionToVisible(table); IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(table, true)); if (row != -1 && col != -1) { int newEditingRow = row + delta; if (newEditingRow != -1 && newEditingRow < rowCount) { table.editCellAt(newEditingRow, col); } } } } myUpAction = new MoveRunnable(-1); myDownAction = new MoveRunnable(1); }