I am new to using TableCellRenderers. I have used the Orcale documentation and some videos to get one that works. To call the renderer I am using the code:
table.getColumnModel().getColumn(x).setCellRenderer(new Renderer());
For my table, I want to use this for each row. I have tinkered around replacing the columns with rows, but my IDE shows that they're no methods by this name, which I am quite surprised by.
Is there some sort of code that can getRow(x)?
renderer code if needed (the argument was taken out the code above for simplification)
int t;
public Renderer(int x){
this.t=x;
}
@Override
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
JLabel x = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
if(t==1){
x.setBackground(Color.GREEN);
}else{
x.setBackground(Color.WHITE);
}
return x;
}
}
You can override prepareRenderer method of JTable