A problem I can see you facing is the structure of your ArrayList
. It is only one dimensional. Data in a JTable
/TableModel
needs to be two dimensional rows/columns
If you made your getinformationforthetable()
return an ArrayList<ArrayList<String>>
then you would be able to more easily populate your table.
Also you might as well just extends DefaultTableModel
. I don't see any special functionality added to your AbstractTableModel
. Then you can just use the method addRow
of DefaultTableModel
to add rows. Something like this
DefaultTableModel model = new MyDefaultTableModel();
E e = new E();
ArrayList<ArrayList<String>> list = e.getinformationforthetable();
for (ArrayList<String> row : list) {
model.addRow(row.toArray());
}
table.setModel(model);
Or don't even extend DefaultTableModel
at all. You can just override it's getColumnClass()
, something like this
private static final String[] COLUMN_HEADERS =
{
"Title", "Artist", "Gengre", "Quality", "Duration","Favorite"
};
DefaultTableModel model = new DefaultTableModel(COLUMN_HEADERS, 0) {
@Override
public Class getColumnClass(int column) {
switch (column) {
case 0: return String.class; break;
case 1: return String.class; break;
...
}
}
};