1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public static void addRowSorter(JTable table, TableModel model) {
//table.setRowSorter(new TableRowSorter<TableModel>(model));
try {
Class tableRowSorterClass = Class.forName("javax.swing.table.TableRowSorter");
Constructor ctor = tableRowSorterClass.getConstructor(new Class[] { TableModel.class });
Object rowSorter = ctor.newInstance(model);
Method method = table.getClass().getMethod("setRowSorter", new Class[] { tableRowSorterClass });
method.invoke(table, new Object[] { rowSorter });
} catch (ClassNotFoundException e) {
log.debug("ClassNotFoundException: " + e.getMessage());
// Nothing to be done, JVM < 6
} catch (NoSuchMethodException e) {
log.error("NoSuchMethodException: " + e.getMessage());
} catch (InvocationTargetException e) {
log.error("InvocationTargetException: " + e.getMessage());
} catch (IllegalAccessException e) {
log.error("IllegalAccessException: " + e.getMessage());
} catch (ClassCastException e) {
log.error("ClassCastException: " + e.getMessage());
} catch (Throwable e) {
log.error("Throwable: " + e.getClass().getName() + " - " + e.getMessage());
}
} |