JTable - Cannot set background color of selected cell

Hi,

I want to set the background color of the selected cell but the renderer colors the slected cell AND some neighbouring cells as well. Please can any one tell me what is the wrong thing I am doing

privateclass SpecialCellRendererextends JLabelimplements TableCellRenderer

{

public SpecialCellRenderer()

{

this.setOpaque(true);

}

public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected,boolean hasFocus,int row,int col)

{

if (hasFocus && isSelected)

{

setBackground(TABLE_SELECTED_COLOR);

}

else

{

setBackground(TABLE_UNSELECTED_COLOR);

}

}

returnthis;

}

[1489 byte] By [Rheaa] at [2007-11-27 3:05:19]
# 1

I find it easier to override the prepareRenderer() method, for something like this. If your table uses multiple types of data in each column then you need a custom renderer for each column. If you override the prepareRenderer() method then you only have the code in one place for all renderers.

camickra at 2007-7-12 3:50:44 > top of Java-index,Desktop,Core GUI APIs...