Вы можете попробовать это:
import java.util.ArrayList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
public class Test {
public static void main(String[] args) {
ArrayList<Teacher> list = new ArrayList<Teacher>();
Teacher a = new Teacher("1", "Max", "Wonder", "012345", "not so good");
Teacher b = new Teacher("2", "Brad", "Summer", "98765", "excellent");
list.add(a);
list.add(b);
JTable table = new JTable();
String headers[] = { "ID", "First_Name", "Last_Name", "Phone", "Experience" };
DefaultTableModel model = new DefaultTableModel(headers, 0);
table.setModel(model);
for (Teacher teacher : list) {
String id = teacher.getId();
String first_Name = teacher.getFirst_Name();
String last_Name = teacher.getLast_Name();
String phone = teacher.getPhone();
String experience = teacher.getExperience();
Object[] data = { id, first_Name, last_Name, phone, experience };
model.addRow(data);
}
System.out.println(table.getValueAt(0, 0));
System.out.println(table.getValueAt(1, 1));
}
}
И класс учителя, как:
public class Teacher {
private String id, first_Name, last_Name, phone, experience;
public Teacher(String id, String first_Name, String last_Name, String phone, String experience) {
this.id = id;
this.first_Name = first_Name;
this.last_Name = last_Name;
this.phone = phone;
this.experience = experience;
}
public String getId() {
return id;
}
public String getFirst_Name() {
return first_Name;
}
public String getLast_Name() {
return last_Name;
}
public String getPhone() {
return phone;
}
public String getExperience() {
return experience;
}
}
Printline только для проверки, если таблица не пуста.
Вывод из примера: 1 бред