【发布时间】:2016-02-07 18:35:22
【问题描述】:
我有一个 5 列的表(1-2-3 字符串 4 整数 5 双精度) 当我尝试按最后两列对表格进行排序时,它的排序不正确。
我尝试使用比较器,但我的表模型得到 IndexOutOfBoundsException
private String[] colonne = {"Barcode", "Modello", "Descrizione",
"Quantitativo", "prezzo"};
//other code
DefaultTableModel tableModel = new DefaultTableModel(colonne, 0);
//other code
table = new JTable(tableModel);
TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<DefaultTableModel>(tableModel);
sorter.setComparator(0, new Comparator<String>() {
@Override
public int compare(String o1, String o2)
{
return Integer.parseInt(o1) - Integer.parseInt(o2);
}
});
table.setRowSorter(sorter);
我该如何解决这个问题?
【问题讨论】:
-
如需尽快获得更好的帮助,请发帖minimal reproducible example 或Short, Self Contained, Correct Example。
标签: java swing sorting jtable comparator