我有一个由列组成的 jtable :
C No, Borrower, Market, Loan, Start, Daily, Expiry
如果当前日期距离 'expiry'
列内的日期还有 5 天,我如何突出显示表格行?
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);
}
}
最佳答案
因为您想要突出显示同一行中的每个单元格作为合格的 Expiry
,您应该覆盖 prepareRenderer()
,如图所示 example并在此 Q&A 中讨论.您可以使用 Calendar 的方法确定匹配的行。 getInstance()
,您可以使用渲染器的 setBackground()
方法更改颜色。
关于java - 如果给定条件,如何突出显示行表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9714110/