I've to color text in cells of one column if value in it is greater than zero. I known, that there was already asks like this, but i can't find working solution despite several hours of searching. Everything gives me some errors. Solution, that gives me least errors is this:
public class MyRenderer extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
{
Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
c.setForeground(Color.RED);
double values = Double.parseDouble(c.getInputContext().toString());
if(column == 2){
if(values > 0){
c.setForeground(Color.GREEN);
}
}
return c;
}
}
however when i've get references to this like that:
MyRenderer.getTableCellRendererComponent(table, "ok", true, true, 2, 2);
It gives me this error:
Cannot make a static reference to the non-static method getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int) from the type bitc.MyRenderer
But when the method is static, the method gives me this error...:
This static method cannot hide the instance method from DefaultTableCellRenderer
And i've got no idea how to bypass this.