【发布时间】:2016-04-22 02:24:19
【问题描述】:
我有一个 jtable。 (表格摘要)。其中一列是 EXPIRY。我想突出显示其到期日期已在当前日期失效的客户的行..
我已经掌握了逻辑,但我无法使该行变为红色或任何其他颜色。 这是我的代码:
int count = (tableSummary.getRowCount());
NumberFormat formatter = new DecimalFormat("###,###");
String no = formatter.format(count);
txtNo.setText(no);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
String expDateString = sdf.format(cal.getTime()).toString();
for(int i=0; i<=tableSummary.getRowCount()-1; i++){
String nnn= tableSummary.getModel().getValueAt(i, 6).toString();
System.out.println(nnn);
int res = nnn.compareTo(expDateString);
if(res>=0){
System.out.println("if ni " + (res>=0));
}
else{
System.out.println("else ni" + (res>=0));
rowrenderer.setBackground(Color.RED);
}
}
谁能帮我解决这个问题?因为它是我界面的主要亮点之一。 提前致谢 !! :)
【问题讨论】:
-
显示“rowrenderer”的定义。
-
你忘记为你的 cellrenderer 添加代码
-
如here 所述,您应该将
Date存储在您的TableModel中。
标签: java swing netbeans jtable