我想爲表格行着色,具體取決於第3列是否存在非空值。 繼承人,我寫的代碼:(忽略括號)Java着色表格行
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
JComponent c =(JComponent) super.prepareRenderer(renderer, row, column);
c.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY, 1));
if (column == 2){
String value = (String) getValueAt(row, column);
System.out.println(value);
if (! value.equals(null)){
c.setForeground(Color.RED);
}
}
問題是,當我執行這一切的表中的行獲得彩色即使只有1排在第3列一個非空值。 我哪裏錯了?
什麼是超級,它返回什麼? – Bozho 2010-01-05 04:48:50
prepareRenderer方法在擴展JTable的類中 – Goutham 2010-01-05 04:55:16
放置一個System.out.println(value)並在調用該方法時檢查實際值。 – Bozho 2010-01-05 05:01:03