I am having issues setting the background color of a Jlabel in a Jtable, once ImageIcon is set. The problem is that when a row is selected, every cell but the one with an image icon reflects the selection color, while the cell with the ImageIcon shows the defailt background color, regardless of selection.
Here is the code for my TableCellRenderer which is not working :
TableCellRenderer tcr = new TableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int col){
JLabel jl = new JLabel();
try {
if (value.toString().substring(0,1).equals("*")){
String fl = "/Users/XXX/XXX/FEEDICONS/"+rs.getInt("feed_id")+".png";
jl.setText(value.toString().substring(1));
jl.setIcon(new ImageIcon(fl));
if (isSelected) jl.setBackground(new Color(180,213,255));
return (Component) jl;
} else {
TableCellRenderer dtcr;
dtcr = table.getDefaultRenderer(Object.class);
return dtcr.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,col);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return null;
}
};
I am fairly new to Java/Swing so, most likely I'm missing something obvious.
Any help is appreciated. Thanks!