Have your class extend something like a JLabel, then have your class implement the TableCellRenderer interface. your code should look something like:
public class MyTableCellRenderer extends JLabel implements TableCellRenderer
{
}
You will need to implement the methods required, but the one you are looking for is getTableCellRendererComponent.
public class MyTableCellRenderer extends JLabel implements TableCellRenderer
{
// This method is called each time a cell in a column
// using this renderer needs to be rendered.
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int rowIndex, int vColIndex)
{
Color bg = Color.WHITE;
//set the background of the required cell
if(rowIndex == 0 && vColIndex == 0)
{
bg = Color.BLUE;
}
setBackground(bg);
// Configure the component with the specified value
setText(value.toString());
// Since the renderer is a component, return itself
return this;
}
}
You can try using this code, however I have not tested it, but it should give you an idea.