There are other ways to do it but I'll suggest doing it using the JIDE approach. The logic behind this approach is you never want to touch the cell renderer when sorting. The cell renderer is a UI component. It is slow.
Step 1: get rid of your CustomTableCellRenderer. Never use a cell renderer if it can be done using an ObjectConverter because it is just a simple string conversion. Instead of using cell renderer, create an ObjectConverter and register it on ObjectConverterManager using int.class with a ConverterContext("whatever_name_you_want"). In your table model, implement ContextSensitiveTableModel and return int.class in getColumnClassAt and ConverterContext("whatever_name_you_want") in getConverterContexAt.
After step 1, you will be able to see the integers are displayed as "BUY" etc. without using a cell renderer. If not, please refer to the developer guide and examples to get it working.
Step 2: Write a special Comparator<Integer> which uses the ObjectConverter you created in step 1 and convert the int values to String first, then compare. Register the Comparator to ObjectComparatorManager using int.class and new ComparatorContext("whatever_name_you_want").
Step 3: Use the Comparator you created in step 2. You need to create a SortableTableModel (the JIDE's SortableTableModel, not the SortableTableModel you created. You should consider rename your SortableTableModel to something else. Otherwise it will be confusing). Using
- Code: Select all
SortableTableModel model = new SortableTableModel(yourModel);
model.setColumnComparatorContextProvider(...); // make sure you return ComparatorContext("whatever_name_you_want") for that column.
SortableTable table = new SortableTable(model);