如何在循环中加载这些变量的数据

时间:2015-05-24 12:03:21

标签: java arrays jtable

如何在循环中创建(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) }
};

1 个答案:

答案 0 :(得分: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);

}