Here you can find the source of createTableRowSorter(Class
public static final <T extends Comparable<T>> TableRowSorter<TableModel> createTableRowSorter(Class<T> clazz, TableModel model)
//package com.java2s; //License from project: Open Source License import java.util.Comparator; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; public class Main { public static final <T extends Comparable<T>> TableRowSorter<TableModel> createTableRowSorter(Class<T> clazz, TableModel model) {// www. j a v a2 s .com final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); final Comparator<T> comp = new Comparator<T>() { @Override public int compare(T o1, T o2) { return o1.compareTo(o2); } }; for (int i = 0; i < model.getColumnCount(); i++) { sorter.setComparator(i, comp); } return sorter; } public static final <T extends Comparable<T>> TableRowSorter<TableModel> createTableRowSorter(Class<T> clazz, TableModel model, Object... columnMap) { final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); final Comparator<T> comp = new Comparator<T>() { @Override public int compare(T o1, T o2) { return o1.compareTo(o2); } }; final Comparator<T> compInverse = new Comparator<T>() { @Override public int compare(T o1, T o2) { return o2.compareTo(o1); } }; for (int i = 0; i < columnMap.length; i++) { final boolean invert = (boolean) columnMap[i + 1]; sorter.setComparator((int) columnMap[i], invert ? compInverse : comp); } return sorter; } }