I have JTable with custom renderer which sets icon in cell.
myTable.setDefaultRenderer(MyClass.class, new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(...) {
JLabel label = table.getTableCellRendererComponent(...);
label.setIcon(iconMap.get( object_type );
return label;
}
});
Where iconMap holds references to different icons, and object_type is a type based on which I want icon to be displayed next to label. As a result table displays cells in one of the columns with icons distinct based on type. This is a behavior which is expected.
Next I would like to filter rows based on type, I am using
TableRowSorter<> sorter = new TableRowSorter(myModel);
RowFilter<> filter = new RowFilter<>() {
public boolean include(...) {
if ( expected_type )
return true;
return false;
}
}
sorter.setRowFilter(filter);
myTable.setRowSorter(sorter);
So basically it is done 'by-the-book', nothing breathtaking.
The problem is that cell's icons are displayed as there were no filter set.
Running application without filtering will display two columns, with proper match of pair icon-type <-> object-type
| A-type-icon | A-type-object |
| B-type-icon | B-type-object |
| B-type-icon | B-type-object |
| B-type-icon | B-type-object |
Running the same with filter which filters A-type-objects will
| A-type-icon | B-type-object |
| B-type-icon | B-type-object |
| B-type-icon | B-type-object |
It looks like objects are rendered first and than filtered. What can I do (or what I am doing wrong) to display icons properly.