回答后续问题
Reason 是默认的通用编辑器:它只能处理具有以 String 作为参数的构造函数的类,而 Character 不能。出路是 Character 类的特定自定义编辑器。
这是 JTable.GenericEditor 抛出的地方:
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int column) {
this.value = null;
((JComponent)getComponent()).setBorder(new LineBorder(Color.black));
try {
Class<?> type = table.getColumnClass(column);
// Since our obligation is to produce a value which is
// assignable for the required type it is OK to use the
// String constructor for columns which are declared
// to contain Objects. A String is an Object.
if (type == Object.class) {
type = String.class;
}
// JW: following line fails
constructor = type.getConstructor(argTypes);
}
catch (Exception e) {
// JW: so the editor returns a null
return null;
}
return super.getTableCellEditorComponent(table, value, isSelected, row, column);
}
这里是 JTable 处理 null 的地方:
// JTable.editCellAt(...)
TableCellEditor editor = getCellEditor(row, column);
if (editor != null && editor.isCellEditable(e)) {
editorComp = prepareEditor(editor, row, column);
if (editorComp == null) {
// JW: back out if the comp is null
removeEditor();
return false;
}