I want to color specific rows in jTable..i did it for columns by using this code,
private class CustomCellRenderer extends DefaultTableCellRenderer {
/* (non-Javadoc)
* @see
javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
*/
@Override
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
Component rendererComp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,row, column);
//Set foreground color
// rendererComp.setForeground(Color.red);
//Set background color
rendererComp .setBackground(Color.pink);
return rendererComp ;
}
}
And i call the above code using,
jTable1.getColumnModel().getColumn(3).setCellRenderer(new CustomCellRenderer());
But i want to do the same for rows in jTable..There’s no getColumnModel() or getColumn() in the case of rows..So what’s the alternate way for doing that? I am doing it in Netbeans by using Java Swing..
Here is an example on how you can combine both column colors and row color. You basically perform tests in the TableCellRenderer to see if the background should be of one color or another.