如果某一个单元格处于编辑状态,当点击JTable以外的组件后,单元格的焦点并不会丢失!!下次你切换回来,那个单元格还持有焦点,要命的是:数据仍然是上次的!!
这应该是JTable的bug,我现在的办法是在每次切换数据以前,都加上这段代码:
TableCellEditor ce = table.getCellEditor();
if (ce != null) {
ce.stopCellEditing();
}大家还有什么好的办法吗?
这应该是JTable的bug,我现在的办法是在每次切换数据以前,都加上这段代码:
TableCellEditor ce = table.getCellEditor();
if (ce != null) {
ce.stopCellEditing();
}大家还有什么好的办法吗?
int col = budgetTable.getSelectedColumn(); if ((row >= 0) && (col >= 0))
{
if (budgetTable.isEditing())
{
budgetTable.getCellEditor(row, col).stopCellEditing();
} if (budgetTable.getCellEditor(row, col).getCellEditorValue() == null)
{
((BudgetTableModel) budgetTable.getModel()).setValueAt(new Integer(0), row, col);
}
}
在主从表的编辑中,用JTable做从表的情况很多,用户往往输入完从表的数据,就切换主表记录。这样JTable却把上一个从表的数据带到了下一条记录,真是恶心透了,被测试员提了很多bug...
另外,当你双击选中单元格时,编辑器由JLabel变为JTextField,所以当你选中别的单元格,编辑器由JTextField变为JLabel,因此仍然有焦点,此时必须连打两次回车,数据才会从视图更新到模型,一切就正常了。