[英]JTable does not show the result on the first execution
The code is to add the data to the JTable. 代码是将数据添加到JTable中。
String [] header = new String [] {"No","Customer","Video","Date","Days","Status-Closed"};
Contract [] contractArray = contractList.toArray(new Contract [contractList.size()]);
Object [][] datarow = new Object [contractArray.length][6];
try{
//Read the objects from file and store in the List
ObjectInputStream inputStream = new ObjectInputStream(
new FileInputStream("contractfile"));
Object o = inputStream.readObject();
while(o != null){
Contract c = (Contract) o;
contractList.add(c);
o = inputStream.readObject();
}
inputStream.close();
} catch (EOFException ex) {
//
}
//Push data to the array
int no = 0;
for(int i = 0; i < contractArray.length; i++){
no++;
datarow[i][0] = no;
datarow[i][1] = contractArray[i].getAccount().getName();
datarow[i][2] = contractArray[i].getVideo().getName();
datarow[i][3] = contractArray[i].getDate();
datarow[i][4] = contractArray[i].getDay();
datarow[i][5] = contractArray[i].getClosed();
}
//set the table model
TableModel mod = new DefaultTableModel(datarow,header);
table.setModel(mod);
The first time I click the button, the table just show the header, click the second time the data was put into the table. 第一次单击按钮时,表格仅显示标题,第二次将数据放入表格中。 When debugging, the first time the datarow[][]
has no element, the second time it had all the objects. 调试时,第一次datarow[][]
没有元素,第二次它拥有所有对象。 Why, could anyone help me out please?? 为什么,有人可以帮我吗?
You call Contract [] contractArray = contractList.toArray(new Contract [contractList.size()]);
您调用Contract [] contractArray = contractList.toArray(new Contract [contractList.size()]);
before loading the list from file. 从文件加载列表之前。 So the size() == 0. 所以size()== 0。
After that datarow = new Object [contractArray.length][6];
在那datarow = new Object [contractArray.length][6];
but the length is 0 但长度为0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.