0
代碼是將數據添加到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);
我第一次單擊該按鈕,該表只顯示標題,單擊該數據被放入表中的第二次。調試時,datarow[][]
第一次沒有元素,第二次有所有的對象。 爲什麼任何人都可以幫助我?
噢,我的壞,這樣的錯誤。非常感謝 –