【发布时间】:2014-12-22 01:45:23
【问题描述】:
我正在制作一个销售点系统,我在这里有两张桌子,tableOne 和 tableTwo。 我想要做的是单击 tableOne 中的一行,它将出现在 tableTwo 中
但我的控制台出现错误
"java.lang.ArrayIndexOutOfBoundsException: 4 >= 4"
我的代码工作正常,当我的控制台上显示该错误时,我只需继续单击行即可。如何消除错误?
// row,col is the row and column in tableOne ( Where we will get the data )
// trow,trow is the row and column in tableTwo ( Where we will put the data )
public void tebel(){
table.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
if(e.getClickCount() == 2) {
target = (JTable)e.getSource();
int row = target.getSelectedRow();
int col= 0;
int trow = 0;
int tcol = 0;
if(row>=0){
while(tcol<=tableOne.getColumnCount()){
tableTwo.setValueAt(tableOne.getValueAt(row,col),trow,tcol);
col++;
tcol++;
if(tcol==tableOne.getColumnCount()){
trow++;
}
}
}
}
}
});
}
【问题讨论】:
标签: java swing jtable mouselistener