Java JTable change cell color

后端 未结 7 1485
说谎
说谎 2020-11-30 14:14

I would like to make an editable table and then check the data to make sure its valid. Im not sure how to change the color of just one cell. I would like to get a cell, for

相关标签:
7条回答
  • 2020-11-30 14:43
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
            int row, int col) {
        Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
        int control = row;
        control = control % 2;
        control = (control == 0) ? 1 : 0;
        if (control == 1) {
            c.setBackground(Color.green);
        } else {
            c.setBackground(Color.cyan);
        }
        return c;
    }
    
    0 讨论(0)
提交回复
热议问题