JTable > Row selection background color
Hello,
I am using an image as a background for my JTable. To do so, I had to install a renderer:
public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
{
Component c = super.prepareRenderer( renderer, row, column);
c.setForeground(Color.BLUE); //change foreground
((JComponent) c).setBorder(null);//remove cell borders
if( c instanceof JComponent)
((JComponent)c).setOpaque(false);
return c;
}
The last three lines above prevent me from seeing which rows are selected.
Is there a command to enable having a background image and see the background color of the selected rows as well?
Thanks
[705 byte] By [
Sialikasa] at [2007-11-26 22:37:18]

# 1
hey,
I had a similar problem when it came to selecting cells, n what i figured out,
the renderer also handles this events. so u need to add these lines
or something similar.
if(isSelected){
setBackground(table.getSelectionBackground());
} else{
setBackground(table.getBackground());
}
if(hasFocus){
Border selectedBorder = BorderFactory.createMatteBorder(1,1,1,1,new Color(99,130,191));//Blue-Border
setBorder(selectedBorder);
} else{
setBorder(null);
}
about the picture, sorry i don't a clue.
the renderer handles each cell separately.
What i think is going to happen is the picture will be displayed in each cell.
avdzma at 2007-7-10 11:48:15 >
