所以我试图在jTable中清除一行数据,但是当我到达最后一行并清除它时,它会清除......但是给我一个错误“行索引超出范围”需要帮助请:D
//Get table model.
DefaultTableModel model = (DefaultTableModel) tblStock.getModel();
//Create variable.
int selectedProduct = tblStock.getSelectedRow();
//Remove selected row.
model.removeRow(selectedProduct);
//Clear selection.
tblStock.clearSelection();
//Set intervals.
tblStock.setRowSelectionInterval(0, 0);
tblStock.setRowSelectionInterval(selectedProduct, selectedProduct);
}
答案 0 :(得分:2)
好的,让我们再看一遍:
int selectedProduct = tblStock.getSelectedRow();
model.removeRow(selectedProduct);
tblStock.setRowSelectionInterval(selectedProduct, selectedProduct);
好像你要删除一行,然后尝试选择它。实际上,在您删除索引后,索引很可能超出范围。