How can I convert JTable
Vector
to JTable
ArrayList
? I changed all vector to arraylist, but I see some issue in calling DefaultTableModel
. I have problem in converting the ArrayList
to 2D array. Please help.
Here is my code:
String headers[] = {"Pick Columns"};
rows = new ArrayList<String>();
columns = new ArrayList<String>();
addColumns(headers, columns);
tabModel = new DefaultTableModel(convertTowDArray(rows.toArray()), headers);
table = new JTable(tabModel);
Here are the methods:
private Object[][] convertTowDArray(Object[] toArray) {
Object[][] o = null;
for (int i = 0; i < toArray.length; i++) {
o[i][0] = toArray[i];
}
return o;
}
public void addColumns(String[] colName, List<String> col)// Table Columns
{
col.addAll(Arrays.asList(colName));
}