我输入我的代码:如何添加一个自定义的CellEditorListener到我的JTable?
private void addMyCellEditorListener() {
class MyCellEditorListener implements CellEditorListener
{
public MyCellEditorListener() {}
public void editingCanceled(ChangeEvent e) {}
public void editingStopped(ChangeEvent e) {
if(row == 0 && column > 0)
rechargeTableWithFindedResults(graphicTable.getValueAt(row,column));
else
dataTable.setValueAt(graphicTable.getValueAt(row,column),row,column);
}
};
.... addCellEditorListener(new MyCellEditorListener());
}
我想我graphicTable
检测数据变为它的细胞通过给它定制CellEditorListener
,但我真的不明白如何添加它。我试了几次用类似下面的代码:
DefaultCellEditor editor = new DefaultCellEditor(new JTextLabel());
editor.addCellEditorListener(new MyCellEditorListener());
this.graphicTable.setCellEditor(editor);
...或:
this.graphicTable.setCellEditor(this.graphicTable.getCellEditor().addCellEditorListener(new MyCellEditorListener()));
...但是这些技术给我一个NullPointerException
在这两种情况下。
我环顾四周通过论坛获得解决方案,但他们只是让我更困惑。
每一个提示将不胜感激。
在此先感谢。
为更好的帮助,尽快发布一个[SSCCE](http://sscce.org/),短的,可运行的,可编译的 – mKorbel