У вас не совсем то, что нужно. Да и слишком сложно. Сделал проще.
Вот мой код:
Код | JTable table = new JTable(aTempStr, columnNames) { private static final long serialVersionUID = -6543930525582285652L; public TableCellRenderer getCellRenderer(int row, int column) { DefaultTableCellRenderer tcr = (DefaultTableCellRenderer) super .getCellRenderer(row, column); if (column == 17) { Object data = this.getValueAt(row, column); SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd"); try { Date parsedDate = format.parse(data.toString()); Calendar calOne = Calendar.getInstance(); calOne.setTime(parsedDate); Calendar calTwo = Calendar.getInstance(); calTwo.add(Calendar.MONTH, -2); Calendar distinct = Calendar.getInstance(); distinct.setTime(new Date(calTwo.getTime() .getTime() - calOne.getTime().getTime())); if (distinct.get(Calendar.MONTH) <= 2) { tcr.setBackground(new Color(255, 125, 125)); } else { tcr.setBackground(new Color(75, 125, 75)); } } catch (Exception e) { System.out.println(e.getMessage()); } } else tcr.setBackground(Color.WHITE); return tcr; } };
|
Только чё-т я не пойму как закрашивать не ячейку, а целую строку, в которой для ячейки выполняется условие:
Код | if (distinct.get(Calendar.MONTH) <= 2) { tcr.setBackground(new Color(255, 125, 125)); } else { tcr.setBackground(new Color(75, 125, 75)); }
|
|