DefaultTableModel () { DefaultTableModel model = new DefaultTableModel() { private String firstResultPath; private final Comparator<Vector<FindPopupItem>> COMPARATOR = (v1, v2) -> { FindPopupItem u1 = v1.get(0); FindPopupItem u2 = v2.get(0); String u2Path = u2.getPath(); String u1Path = u1.getPath(); if (u1Path.equals(firstResultPath) && !u2Path.equals(firstResultPath)) return -1; // first result is always sorted first if (!u1Path.equals(firstResultPath) && u2Path.equals(firstResultPath)) return 1; int c = u1Path.compareTo(u2Path); if (c != 0) return c; c = Integer.compare(u1.getLine(), u2.getLine()); if (c != 0) return c; return Integer.compare(u1.getNavigationOffset(), u2.getNavigationOffset()); }; @Override public boolean isCellEditable(int row, int column) { return false; } @SuppressWarnings({"UseOfObsoleteCollectionType", "unchecked", "rawtypes"}) @Override //Inserts search results in sorted order public void addRow(Object[] rowData) { if (myNeedReset.compareAndSet(true, false)) { dataVector.clear(); fireTableDataChanged(); } Vector<FindPopupItem> v = (Vector)convertToVector(rowData); if (dataVector.isEmpty()) { addRow(v); myResultsPreviewTable.getSelectionModel().setSelectionInterval(0, 0); firstResultPath = v.get(0).getPath(); } else { int p = Collections.binarySearch((Vector<Vector<FindPopupItem>>)((Vector)dataVector), v, COMPARATOR); if (p < 0) { // only insert when not already present. int row = -(p + 1); insertRow(row, v); } } } }; model.addColumn("Usages"); return model; }