回答後續問題
原因是默認的通用編輯器:它可以只處理具有以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