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..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…