基于单元格值的Jtable单元格字体颜色

时间:2017-02-14 15:06:52

标签: jtable

class CustomTableRenderer 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);
          String s = table.getModel().getValueAt(row,12).toString();                    
            if(s.equals("Filled") && column == 12)
            {
                setForeground(Color.RED);


                System.out.println("Inside " + s + column);
            }

        return c;
    }}

使用上面的代码,所有列的颜色都在变化,我想根据值在单列上进行更改。

1 个答案:

答案 0 :(得分:0)

忽略上述问题。我得到了相同的答案。