如何在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);
答案 0 :(得分:0)
你可以维护一个整数 i
并在循环中你可以做
row [i] = item ;
P.S你必须检查null
,length
等以避免exceptions
......
答案 1 :(得分:0)
Object[] row = new Object[number_of_element];
for(int i = 0; i < number_of_object; i++)
row[i] = (Object)item;
另外,要注意你在for循环中创建行数组,它应该在循环之外