Colorir as células de uma coluna da jTable individualmente

0 respostas
alexwebsp

Boa Noite ! Gostaria de colorir as células indidualmente, criei um método mas ele está colorindo a coluna e não as células individuais

public class ColorirCelula extends DefaultTableCellRenderer  {
    
    private static final long serialVersionUID = 433648737270300478L;

    private Map _cores = new HashMap();

    private Point _tempCel = new Point(0, 0);

    @SuppressWarnings({"unchecked", "unchecked"})
    public ColorirCelula(int row, int col, boolean condicao) {
        
        this._tempCel.x = row;
        this._tempCel.y = col;

        if(condicao==true)
            {
            this._cores.put(new Point(row, col), Color.GREEN);
            }
            else
                {
                this._cores.put(new Point(row, col), Color.RED);
                }       
       
    }

    @Override
    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);
               
        if (this._cores.containsKey(this._tempCel)) {
            c.setBackground((Color) this._cores.get(this._tempCel));
            
            
        } else {
            c.setBackground(Color.WHITE);
            
        }
        
        return c;
        
    }

Aí eu chamo assim:

jTable.getColumnModel().getColumn(2).setCellRenderer(new ColorirCelula(a, 2, true));

Por favor me ajudem, já pesquisei muito na internet, eu quero colorir as células individuais, Obrigado.

Criado 15 de abril de 2010
Respostas 0
Participantes 1