JTable实时获取单元格结束编辑之前的值
思路:重写table的editingStopped方法,在结束编辑之前获取单元格的值,并保存在变量中。
String editValue = "";
table = new JTable(MyTableModel){
private static final long serialVersionUID = 1L;
public void editingStopped(ChangeEvent changeevent)
{
int r=getEditingRow();
int c=getEditingColumn();
System.out.println(r+"--"+c);
editValue = (String)table.getValueAt(r, c);
System.out.println(editValue);
TableCellEditor tablecelleditor = getCellEditor();
if(tablecelleditor != null)
{
Object obj = tablecelleditor.getCellEditorValue();
setValueAt(obj, editingRow, editingColumn);
removeEditor();
}
}
};
还没有评论,来说两句吧...