问题
I have a jtable which is consists of columns :
C No, Borrower, Market, Loan, Start, Daily, Expiry
how can i highlight the table row if the current date is 5 days away from the date inside the column 'expiry'?
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
String expDateString = sdf.format(cal.getTime()).toString();
System.out.println(expDateString);
String nana = tableSummary.getModel().getValueAt(row, 6).toString();
System.out.println(nana);
for(int i=0; i<=tableSummary.getRowCount()-1; i++){
if(nana.compareTo(expDateString)>=0){
rowrenderer.setBackground(Color.RED);
}
}
回答1:
Because you want to highlight every cell in the same row as a qualifying Expiry, you should override prepareRenderer(), as shown in this example and discussed in this Q&A. You can determine a matching row using the methods of Calendar. getInstance(), and you can change the color using the renderer's setBackground() method.
来源:https://stackoverflow.com/questions/9714110/how-to-highlight-row-table-if-given-a-condition