拜托,谁能明白为什么这段代码仍然拒绝使用我的比较器?这是与 userTable 对象相关的所有代码 + 我在那里有鼠标和键侦听器,但我认为它不会影响排序。
private TableRowSorter trs;
public constructor() {
initComponents();
...
trs = new TableRowSorter<>(userTable.getModel());
class IntComparator implements Comparator {
@Override
public int compare(Object o1, Object o2) {
System.out.println("comparing");
Integer int1 = (Integer) o1;
Integer int2 = (Integer) o2;
return int1.compareTo(int2);
}
}
trs.setComparator(0, new IntComparator());
userTable.setRowSorter(trs);
...
}
private void initComponents() {
...
userTable = new javax.swing.JTable(){
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
return renderer;
}
};
...
userTable.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"ID", "count", "null"
}
) {
Class[] types = new Class [] {
java.lang.Integer.class, java.lang.Integer.class, java.lang.Object.class
};
boolean[] canEdit = new boolean [] {
false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
}
它一直在进行 RADIX 排序,并且从未显示过消息“比较”。谢谢你。