Problems with a cell renderer

I'm experimenting with cell renderers for JTables.

I tried to add a renderer so that I could change the colour of the text that is displyed depending on whether or not data has been selected.

Once the renderer has been added, all that happens for that column is that no data is displayed and the column cannot even be selected!

private class MyCellRenderer extends JLabel implements TableCellRenderer

{.........

public Component getTableCellRendererComponent(JTable table, Object text,

boolean isSelected, boolean hasFocus, int row, int column)

{// If the cell has been selected then we will change its text to red.

// If it has been de-selcted it will be blue.

if (isSelected)

{setForeground(Color.red);

}

else

{setForeground(Color.blue);

}

setToolTipText("First Name: " + text);

return this;

}....

any help! please?!

[935 byte] By [buff5000] at [2007-9-30 19:39:44]
# 1

private class MyCellRenderer extends JLabel implements TableCellRenderer {

public Component getTableCellRendererComponent(JTable table,

Object text, boolean isSelected, boolean hasFocus, int row,

int column) { // If the cell has been selected then we will

// change its text to red.

// If it has been de-selcted it will be blue.

if (isSelected) {

setForeground(Color.red);

} else {

setForeground(Color.blue);

}

setText(text.toString());

setToolTipText("First Name: " + text);

return this;

}

minyuancom at 2007-7-7 0:24:30 > top of Java-index,Administration Tools,Sun Connection...