如果我们在表中有n行并删除其索引为n-1的行,则此代码为Ok,但是当我删除其索引为n的行(或删除行之后的任何行)时,我会捕获索引约束异常! 我该如何解决这个问题?
Thread registerThread = new Thread(){
public void run(){
try{
int i =JOptionPane.showConfirmDialog(view, "Are you sure to delete these IP and port?" );
if(i == 0){
int selectedRow = workerMachineTable().getSelectedRow();
System.out.println("selected row" + selectedRow);
unRegister(selectedRow);
dataModel.removeRow(selectedRow);
}else return;
}catch (Exception e){
JOptionPane.showMessageDialog(view, e.getMessage(), "Error", 2);
e.printStackTrace();
}
}
};
答案 0 :(得分:0)
从所选行中减去一个
int selectedRow = view.getWorkerMachineTable().getSelectedRow() - 1;