Java GUI aplication, load data to Jtable from a list
i have found the following link but i haven't found an answer: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html
please can someone gice me an example how should i do it.
my objects have 5 fields:Name,Grade,Salary,BirthYear,Sex
and the list is readed from a file so i dont know how many ojects will the List have.
I am working in netbeans.
解决方案
The tutorial you linked to has an example: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data. You should be able to adapt it to a List easily:
public int getRowCount() {
return list.size();
}
public int getColumnCount() {
return 5;
}
public Object getValueAt(int row, int col) {
Employee employee = list.get(row);
if (col == 0) {
return e.getName();
}
else if (col == 1) {
return e.getGrade();
}
...
}