Stack Exchange
TableCellRenderer issue with empty cell
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import java.math.BigDecimal;
import javax.swing.JLabel;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author SWDP
 */
public class Renderer extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

        if (value != "null") {

            if (value instanceof String) {
                String s;
                s = String.valueOf(table.getValueAt(row, 3));
                BigDecimal valor = new BigDecimal(s);
                if (column == 3) {

                    if (valor.compareTo(BigDecimal.valueOf(0.001)) >= 0 && valor.compareTo(BigDecimal.valueOf(0.1)) <= 0) {
                        setBackground(Color.green);
                    }

                    if (valor.compareTo(BigDecimal.valueOf(0.1)) > 0 && valor.compareTo(BigDecimal.valueOf(0.9)) <= 0) {
                        setBackground(Color.yellow);
                    }

                    if (valor.compareTo(BigDecimal.valueOf(0.9)) > 0 && valor.compareTo(BigDecimal.valueOf(3.0)) <= 0) {
                        setBackground(Color.pink);
                    }

                    if (valor.compareTo(BigDecimal.valueOf(3.0)) > 0) {
                        setBackground(Color.red);
                    }
                } else {
                    setBackground(Color.white);
                }

            }

        }

        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    }
}`

I want to paint a cell depending on which interval the value is. This code is working well when there is a data in that cell. If the cell is empty I got an error message. Otherwise if there is a null cell an error message is shown and the JTable is shown wrongly.

Welcome to SO, Oscar. It is always good to see what you have done in your code for the community to help acordingly so please show us what you have done so far

Show your pertinent code, preferably as a [mcve], show your error messages, and help make this question answerable.

@Jason Given that Swing is one of the core APIs of Java, I think it's obviously 'both'.

Most likely because you're not checking whether the string is empty and use an empty string to instantiate a BigDecimal in case the cell is empty. Check for null or String.isEmpty in a separate if/else branch first.

I made a validation: if (value != "null") do the validation the value in those intervals. else return the component whithout changes, but it did not work.

as i understand it you want to ignore cells without any value and cells with the value "null". if it is like that you can use if(!value.equals("null")&&value != null). this will then ignore the both cases i listed above
