回答后续问题
原因是默认的通用编辑器:它可以只处理具有以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中处理空值:
// 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;
}
如果您确信isEditable返回true,你可能要检查的这个编辑器柱。 – mort 2012-07-08 14:16:42
看到您的通知,但为了更好地帮助更快地发布[SSCCE](http://sscce.org/)展示您的问题与JTable – mKorbel 2012-07-08 14:18:32
你是什么意思的“设置类型为int”? – kleopatra 2012-07-08 14:48:43