When you click the column header on my JTable, its sorts the rows alphabetically. This works for all of my columns except for one. In this column the values are all Strings, but contain numbers. I need them to be sorted based off of their decimal value and not string value.
Any idea how to accomplish this?
解决方案
please read tutorial about JTable that's contains TableRowSorter example,
your answer is these codes lines, set column Class correctly
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
// or could be in most cases hardcoded, and I'm using that too
@Override
public Class> getColumnClass(int colNum) {
switch (colNum) {
case 0:
return Integer.class;
case 1:
return Double.class;
case 2:
return Long.class;
case 3:
return Boolean.class;
case 4:
return String.class;
case 5:
return Icon.class;
/*case 6:
return Double.class;
case 7:
return Double.class;
case 8:
return Double.class;*/
default:
return String.class;
}
}