I am trying to color a cell of a jTable using the renderers, but they are not working well, as they lag the table and make it impossible to see. here\'s my code:
ok, after looking in the discussion thread, i come to this solution...
...don't try to get the rendered Component itself - tell the renderer to draw your desired component in ways you want it to...
CellRenderer renderer = new DefaultCellRenderer(){
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
JLabel label = (JLabel)c;
if (yourAlgorithmToDetectTheProperCell){ //i can't insert your condition from above, it's overkill ^^
label.setBackGround(Color.RED);
}
return label;
}
};
table.setCellRenderer(renderer);
SDF