0

如何在Object[]类变量中添加元素?我有arrayList包含 DTO 类数据的对象(第 125 行,第 6 列)。我想显示所有数据JTable

String[] columnNames = {"TEST CASE NUMBER", "NO OF EXECUTION", "TOTAL NO OF PASSED", "TOTAL NO OF FAILED", "FINAL RESULT", "DATE & TIME"};

DefaultTableModel model = new DefaultTableModel(columnNames, 0);  

for (Object item : arrayList) {
    Object[] row = new Object[6];

    how to add the element in row ...?

    model.addRow(row);
}
final JTable table = new JTable(model);
4

2 回答 2

0

你可以保持一个整数i和循环你可以做

row [i] = item ;

PS你必须检查nulllength等等以避免exceptions......

于 2013-05-30T06:21:51.583 回答
0
Object[] row = new Object[number_of_element];

for(int i = 0; i < number_of_object; i++)
    row[i] = (Object)item;

另外,请注意在 for 循环内创建行数组,它应该在循环外

于 2013-05-30T06:25:08.637 回答