when i add getcolumn class to my abstracttablemodel, i couldnt use my custom TableCellRenderer to set background color. (i use this for sorting,alignment numeric columns)
<
Use TableColumn#setCellRenderer() to draw individual values for each column.
Just add below lines in your code
MyCustomTableCellRenderer cellRenderer = new MyCustomTableCellRenderer();
for (int i = 0; i < table.getColumnCount(); i++) {
table.getColumnModel().getColumn(i).setCellRenderer(cellRenderer);
}
instead of
table.setDefaultRenderer(Object.class, new MyCustomTableCellRenderer());
and your problem will be solved.
Note: You are using DefaultTableCellRenderer
that will apply on cell hence use setCellRenderer()
instead of setDefaultRenderer()
.
screenshot: (one row is selected)