I have a table cell renderer class, that should color certian cells of a table and leave others the default. The problem is, all the cells take the properties of the last one I set! The text is correct in each of them, but if I set them all blue except the last one, they are all the color of the last one. Here is some of the code. Thanks for any help.
JTable jt = new JTable....
jt.setDefaultRenderer(Class.forName("java.lang.Object", (TableCellRenderer)jt.getModel());
This is the renderer.
public class InstrumentTableModel extends AbstractTableModel implements TableCellRenderer
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column)
{
if(value != null)
{
j = new JLabel(value.toString());
}
else
{
j = new JLabel(""
value = "";
}
j.setOpaque(true);
j.setBackground(Color.getColor(((InstrumentTableModel)table.getModel()).getHighlightedColor(value.toString())));
j.setForeground(Color.getColor(((InstrumentTableModel)table.getModel()).getHighlightedColor(value.toString())));
return j;
}
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
JTable jt = new JTable....
jt.setDefaultRenderer(Class.forName("java.lang.Object", (TableCellRenderer)jt.getModel());
This is the renderer.
public class InstrumentTableModel extends AbstractTableModel implements TableCellRenderer
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column)
{
if(value != null)
{
j = new JLabel(value.toString());
}
else
{
j = new JLabel(""
value = "";
}
j.setOpaque(true);
j.setBackground(Color.getColor(((InstrumentTableModel)table.getModel()).getHighlightedColor(value.toString())));
j.setForeground(Color.getColor(((InstrumentTableModel)table.getModel()).getHighlightedColor(value.toString())));
return j;
}
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.