• TableRowSorter sorter = new TableRowSorter(table.getModel());
  • table.setRowSorter(sorter);
  • Comparator comparatorNumber = new Comparator() {
  • @Override
  • public int compare(String s1, String s2) {
  • if (s1.compareTo("N/A") != 0 && s2.compareTo("N/A") != 0) {
  • return ((BigDecimal) NumberUtils.parseNumber(s1, BigDecimal.class, EsseRegional.getDecimalFormat())).compareTo((BigDecimal) NumberUtils.parseNumber(s2, BigDecimal.class, EsseRegional.getDecimalFormat()));
  • } else {
  • return -1;
  • }
  • }
  • };
  • for (int i = 0; i < table.getColumnCount(); i++) {
  • if (i == 0) {
  • sorter.setComparator(i, comparatorString);
  • } else {
  • sorter.setComparator(i, comparatorNumber);
  • }
  • }
  • Similar questions and discussions