Hello,
I've encountered a strange behavior from JTable (JDK 1.5_22):
After a selection change in the table and under some unknown particular circumstances, the JTable will call the cell renderer with 'null' for the value parameter.
This will eventually lead to a nice 'Null Pointer Exception' on a custom renderer code that is not ready for such a rude call.
Here is the guilty method (JTable.java, line 5319) :
public Accessible getAccessibleChild(int i) {
if (i < 0 || i >= getAccessibleChildrenCount()) {
return null;
} else {
// children increase across, and then down, for tables
// (arbitrary decision)
int column = getAccessibleColumnAtIndex(i);
int row = getAccessibleRowAtIndex(i);
TableColumn aColumn = getColumnModel().getColumn(column);
TableCellRenderer renderer = aColumn.getCellRenderer();
if (renderer == null) {
Class<?> columnClass = getColumnClass(column);
renderer = getDefaultRenderer(columnClass);
}
Component component = renderer.getTableCellRendererComponent(
JTable.this, null, false, false,
row, column);
return new AccessibleJTableCell(JTable.this, row, column,
getAccessibleIndexAt(row, column));
}
}
and here is a focus on the faulty statement:
Component component = renderer.getTableCellRendererComponent(
JTable.this, null, false, false,
row, column);
Asking google whith "JTable getAccessibleChild 5334" was interesting: I'm not alone to encounter this 'feature'. But there were no answer.
Most well formulated question is located on official sun forum.
Does anyone have a clue about this ?