2015-05-24 58 views
-3

如何在循環中創建這部分(JTable)代碼?如何在循環中加載這些變量的數據

Object[][] dataEntries = 
{ 
     { firstName[0], "secondName[0]", ""Click to select"", new Boolean(false) }, 
     { firstName[1], "secondName[1]", ""Click to select"", new Boolean(false) }, 
     { firstName[2], "secondName[2]", ""Click to select"", new Boolean(false) }, 
     { firstName[3], "secondName[3]", ""Click to select"", new Boolean(false) } 
}; 

Becouse我想這就像

Object[][] dataEntries = 
{ 
     { firstName[i], "secondName[i]", ""Click to select"", new Boolean(false) }, 
     { firstName[i+1], "secondName[i+1]", ""Click to select"", new Boolean(false) }, 
     { firstName[i+2], "secondName[i+2]", ""Click to select"", new Boolean(false) }, 
     { firstName[i+3], "secondName[i+3]", ""Click to select"", new Boolean(false) } 
}; 

回答

0

嘗試這樣的事:

Object[][] dataEntries = new Object[4][4]; 

for(int i = 0 ; i<4 ; i++){ 

    dataEntries[i][0] = firstName[i]; 
    dataEntries[i][1] = "secondName["+i+"]"; 
    dataEntries[i][2] = "Click to select"; 
    dataEntries[i][3] = new Boolean(false); 

} 
+0

你忘了創建第二個維數組。 –

+0

@NarendraPathai謝謝你的回覆,但我沒有忘記:Object [] [] dataEntries = new Object [4] [4];' – Lrrr

+0

謝謝,但我改變 dataEntries [i] [1] =「secondName [」+ 1 + 「]」; 至 secondName [i]; ,因爲它夠了。 – arkani

相關問題