JTable异常删除行

时间:2015-12-08 13:57:52

标签: java swing jtable

当我从Swing JTable中删除一行时,我点击JTable我得到一个例外:

@RequestMapping(value = "/upload", method=RequestMethod.POST)
public Response uploadFile(@RequestBody byte[] file) {
  ...
}

这是我的代码:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.setValueAt(Unknown Source)
at javax.swing.JTable.setValueAt(Unknown Source)
at javax.swing.JTable.editingStopped(Unknown Source)
at javax.swing.AbstractCellEditor.fireEditingStopped(Unknown Source)
at javax.swing.DefaultCellEditor$EditorDelegate.stopCellEditing(Unknown Source)
at javax.swing.DefaultCellEditor$3.stopCellEditing(Unknown Source)
at javax.swing.DefaultCellEditor.stopCellEditing(Unknown Source)
at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(Unknown Source)
at java.awt.AWTEventMulticaster.mousePressed(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)

我已经检查了删除操作之前和之后的行数,一切似乎都正确。我认为有一些与JComboBox组件相关的东西,因为当我删除然后使用带有字符串的单元格时,一切正常。但我真的不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:2)

问题似乎是已删除行的单元格当前处于编辑模式,并且"停止编辑"事件触发已删除的单元格。尝试在删除部分之前停止单元格版本,使用:

DefaultCellEditor dce = (DefaultCellEditor)tableau.getCellEditor(); 
if (dce != null) dce.stopCellEditing();