diff --git a/java/openapi/src/com/intellij/codeInsight/NullableAnnotationsPanel.java b/java/openapi/src/com/intellij/codeInsight/NullableAnnotationsPanel.java index 11f7c0499527..049931d130eb 100644 --- a/java/openapi/src/com/intellij/codeInsight/NullableAnnotationsPanel.java +++ b/java/openapi/src/com/intellij/codeInsight/NullableAnnotationsPanel.java @@ -232,13 +232,19 @@ public class NullableAnnotationsPanel { } private void addRow(String annotation, boolean checked) { - myTableModel.addRow(new Object[]{annotation, checked}); + int row = myTable == null ? -1 : myTable.getSelectedRow(); + if (row == -1) { + myTableModel.addRow(new Object[]{annotation, checked}); + } else { + myTableModel.insertRow(row + 1, new Object[]{annotation, checked}); + } } private Integer selectAnnotation(String annotation) { - for (int i = 0; i < myTable.getRowCount(); i++) { - if (annotation.equals(myTable.getValueAt(i, 0))) { + for (int i = 0; i < myTableModel.getRowCount(); i++) { + if (annotation.equals(myTableModel.getValueAt(i, 0))) { myTable.setRowSelectionInterval(i, i); + myTable.scrollRectToVisible(myTable.getCellRect(i, 0, true)); return i; } } @@ -247,7 +253,7 @@ public class NullableAnnotationsPanel { private @NlsSafe String getSelectedAnnotation() { int selectedRow = myTable.getSelectedRow(); - return selectedRow < 0 ? null : (String)myTable.getValueAt(selectedRow, 0); + return selectedRow < 0 ? null : (String)myTableModel.getValueAt(selectedRow, 0); } private void chooseAnnotation(@NlsSafe String title) { @@ -265,7 +271,7 @@ public class NullableAnnotationsPanel { addAnnotationToCombo(qualifiedName); Object added = selectAnnotation(qualifiedName); assert added != null; - myTable.scrollRectToVisible(myTable.getCellRect((int)added, 0, true)); + myTable.requestFocus(); } } @@ -286,19 +292,19 @@ public class NullableAnnotationsPanel { } public String[] getAnnotations() { - int size = myTable.getRowCount(); + int size = myTableModel.getRowCount(); String[] result = new String[size]; for (int i = 0; i < size; i++) { - result[i] = (String)myTable.getValueAt(i, 0); + result[i] = (String)myTableModel.getValueAt(i, 0); } return result; } List getCheckedAnnotations() { List result = new ArrayList<>(); - for (int i = 0; i < myTable.getRowCount(); i++) { - if (Boolean.TRUE.equals(myTable.getValueAt(i, 1))) { - result.add((String)myTable.getValueAt(i, 0)); + for (int i = 0; i < myTableModel.getRowCount(); i++) { + if (Boolean.TRUE.equals(myTableModel.getValueAt(i, 1))) { + result.add((String)myTableModel.getValueAt(i, 0)); } } return result;