I have a JTable with 3 columns in it. 1. Icon, 2. Name of file or folder, 3. File type or “Folder”. I draw the Icon using a JLabel (I set background + png image) within the getTableCellRendererComponent method. Initially I draw an alternating background of the JLable either “white” or “grey” since those are the colors that the JTable Swing component alternates to draw the table. Now, when I select a row, the Icon (the first column) background does not get redrawn to “dark blue” same as the rest of the row. 
Here are my questions:
General
1) How can also highlight the Icon cell when highlighting a row (pointers will suffice, no code expected)?
Specific
1.1) Do I have to use JLabel? Why can’t I just e.g. .SetValueAt("image.png",0,0)
1.2) I tried the getColumnClass(...) but that seems to redraw ALL cells in a given column. Is that expected?
Thanks.
1.) The
javax.swing.table.TableCellRenderergets anisSelectedparameter when it is called. You can easily write your ownTableCellRendererby inheriting fromJLabel(for example) and overriddinggetTableCellRendererComponent: Adjust the Object and returnthis. Having your own renderer also allows you to set a breakpoint and really understand what is happening.1.1 + 1.2.) Both
setValueAtandgetColumnClassare part if the model and will probably not solve your problem with the selected background.You do not have to use
JLabel: If you look at the return type fromgetTableCellRendererComponentyou notice it isComponent(not evenJComponent). I guessJLabelis just customary because it normally has all the features you want for the renderer and theDefaultTableCellRendereralso usesJLabel. For the most freedom I advise you to useJComponentand write your ownpaintComponent, but in this case you probably don’t have to do that.