TableSorter, how to sort differently depending of order('a-z' vs. 'z-a')
publicstaticfinal Comparator COMPARABLE_COMPARATOR =new Comparator(){
publicint compare(Object o1, Object o2){
if (("".equals(o1) ||"".equals(o2))return ((Comparable) o2).compareTo(o1);
return ((Comparable) o1).compareTo(o2);
}
};
THE OBJECT IS TO GET FIELDS THAT EQUALS("") TO ALWAYS BE SORTED LAST INDEPENDENT OF ORDER.
So for so good, when sorting A-Z it puts the blank in the end,
and as previously stated i want it to put ("") in the end regardless of order.
Ive been trying for quite some time to get this working, but i cant get it right.. Does anyone know, and can tell me how to get make it work..
My guess, is that i need to add to the if statement..
if ("".equals(o1) ||"".equals(o2))
And somehow check if sorting method is reverse (ie. from z-a),
(lets pretend we have a boolean reverse; that keeps track of this.
then i guess the if statement should look like..
if ("".equals(o1) ||"".equals(o2)) && (!reverse)){ return...}
But as i said, i have yet failed to get this type of sorting to work.
I should also declare that i have no such boolean keeping track of sorting either, nor have i been able to implement such a thing.
So i would be most greatful for any help solving this matter!
Thanks in advance!
http://java.sun.com/docs/books/tutorial/uiswing/components/examples/TableSorter.java - TableSorter class in full.
http://specview.stsci.edu/doc/spv/util/TableSorter.html - Doc..

