我重写了AbstractTableModel,但是怎么都无法调用setValueAt,请问是为什么呢另,我还写了自己的DefaultTableCellRenderer,这个类还实现了mouseListener,但是在mouseClick里期望改变一个单元格的值,请问应该怎么写呢 private AbstractTableModel weekModel = new AbstractTableModel() {
public int getColumnCount() {
return 8;
}
public int getRowCount() {
return 13;
}
public Object getValueAt(int rowIndex, int columnIndex) {
System.out.println("get");
Object hour = null;
if (columnIndex == 0) {
switch (rowIndex) {
case (0):
hour = "";
break;
case (1):
hour = "0:00-2:00 am";
break;
case (2):
hour = "2:00-4:00 am";
case (3):
hour = "4:00-6:00 am";
break;
case (4):
hour = "6:00-8:00 am";
break;
case (5):
hour = "8:00-10:00 am";
break;
case (6):
hour = "10:00-12:00 am";
break;
case (7):
hour = "12:00-14:00 pm";
break;
case (8):
hour = "14:00-16:00 pm";
break;
case (9):
hour = "16:00-18:00 pm";
break;
case (10):
hour = "18:00-20:00 pm";
break;
case (11):
hour = "20:00-22:00 pm";
break;
case (12):
hour = "22:00-24:00 pm";
break;
}
} else if (rowIndex == 0) {
if (columnIndex == 0)
hour = "Hour Period";
else {
Calendar temp = (Calendar) calendar.clone();
int today = temp.get(Calendar.DAY_OF_WEEK);
temp.set(Calendar.DATE, calendar.get(Calendar.DATE)
+ columnIndex - today);
hour = (new Integer(temp.get(Calendar.MONTH) + 1))
.toString();
hour = hour
+ "-"
+ (new Integer(temp.get(Calendar.DATE)))
.toString() + "/" + h[columnIndex];
// HashMap<String,DateText> a = new HashMap<String,DateText>();
}
} else {
if (data[rowIndex][columnIndex] == null)
hour = null;
else if(((HashMap<String,DateText>)data[rowIndex][columnIndex]).size() == 0)
hour = null;
else
hour = data[rowIndex][columnIndex];
}
return hour;
}
public void setValueAt(DateText addDate, int row, int column) {
System.out.println("yes");
if (row == 0 || column == 0); 
else {
HashMap<String, DateText> temp = (HashMap<String, DateText>) getValueAt(
row, column);
temp.put(addDate.getTitle(), addDate);
data[row][column] = temp;
System.out.println(temp.size());
this.fireTableCellUpdated(row, column);
}
}
};