-1
public class cellRender extends DefaultTableCellRenderer
{
    @Override
    public Component getTableCellRendererComponent(JTable tblPackage, Object value, boolean isSelected, boolean hasocus, int row, int col)
    {
        Component c = super.getTableCellRendererComponent(tblPackage, value, isSelected, hasocus, row, col);
        if(tblPackage.getColumnModel().getColumn(col).getIdentifier().equals("Package Status"))
        {
            if(value.toString().equals("ACTIVE"))
            {
                c.setBackground(Color.GREEN);
            }
        }
        return this;
    }
}

The symbol shows that it cannot find the symbol...what's the problem with that?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jefferyleo
  • 630
  • 3
  • 17
  • 34

3 Answers3

0

I assume you're talking about a compile time error but I don't have one. This class
compiles fine (and I didn't make any changes to your code except adding import
statements). So check if you have all import statements correct.

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class cellRender extends DefaultTableCellRenderer
{
    @Override
    public Component getTableCellRendererComponent(JTable tblPackage, Object value, boolean isSelected, boolean hasocus, int row, int col)
    {
        Component c = super.getTableCellRendererComponent(tblPackage, value, isSelected, hasocus, row, col);
        if(tblPackage.getColumnModel().getColumn(col).getIdentifier().equals("Package Status"))
        {
            if(value.toString().equals("ACTIVE"))
            {
                c.setBackground(Color.GREEN);
            }
        }
        return this;
    }
}
peter.petrov
  • 38,363
  • 16
  • 94
  • 159
0

In your return statement it should be the component so use the below:

 return c;
Rahul
  • 3,479
  • 3
  • 16
  • 28
0

In your code

return this;

this statement is wrong. Because this refers to the current object and you need to return the component.

So you need to replace this by c like

return c;

EDIT:

Try this I am not sure about this but...

tblPackage.setDefaultRenderer(Object.class, new TableCellRenderer(){
    private DefaultTableCellRenderer DEFAULT_RENDERER =  new DefaultTableCellRenderer();

            @Override
            public Component getTableCellRendererComponent(JTable tblPackage, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
                Component c = DEFAULT_RENDERER.getTableCellRendererComponent(tblPackage, value, isSelected, hasFocus, row, col);
        if(tblPackage.getColumnModel().getColumn(col).getIdentifier().equals("Package Status"))
        {
            if(value.toString().equals("ACTIVE"))
            {
                c.setBackground(Color.GREEN);
            }
        }

                return c;
            }

        });
ravibagul91
  • 20,072
  • 5
  • 36
  • 59