Set the background color of rows with same date

Viewed 123

I need to set the background color of my rows. For example there are these rows:

29.12.14  Absences
12.01.15  Absences
12.01.15  Accounts

Now if there are 2 rows with the same date (above 12.01.15) they should have the same background color in the GUI.

    String week = new String();
    int weekCounter = 0;
    int colour = 0;

    // Append the rows
    for (ExcelRow row : printOutRows) {
        if (weekCounter == 0){
        week = row.getExcelCells().get(0).getExcelCell().getRichStringCellValue().getString();
            colour = 0;
        }
        else if (row.getExcelCells().get(0).getExcelCell().getRichStringCellValue().getString().equals(week)){
            colour = 0;
        }
        else {
            week = row.getExcelCells().get(0).getExcelCell().getRichStringCellValue().getString();
            colour = 1;
        }

        model.addRow(new Object[] {
                row.getExcelCells().get(0).getExcelCell().getRichStringCellValue().getString(),
                row.getExcelCells().get(1).getExcelCell().getRichStringCellValue().getString(),
                row.getExcelCells().get(2).getExcelCell().getRichStringCellValue().getString(),
                row.getExcelCells().get(3).getExcelCell().getNumericCellValue()});  

        if (colour == 0){
            table.setSelectionBackground(Color.RED);
        }
        else{ 
            table.setSelectionBackground(Color.LIGHT_GRAY);
        }
        weekCounter ++;

    }

I tried the code above, but all rows in the JTable are having a white background. How can I reach my goal?

1 Answers
Related