I'm new to JTable , maybe I donโt understand something.
Suppose ArrayList 1000 Students ( id, name, surname, age ). And I want to show all students in JTable . As I understand it, I have to create StudentTableModel that extends AbstractTableModel and set StudentTableModel to JTable . Therefore, we can consider StudentTableModel as an โadapterโ between our ArrayList and table. On the Internet, I found an example implementation of getValueAt :
public Object getValueAt(int row, int col) { Student student = arrayList.get(row); switch (col) { case 0: return student.getId(); case 1: return student.getName(); case 2: return student.getSurname(); case 3: return student.getAge(); } }
The problem is that with 1000 students (rows) and 4 fields (columns) we will run this switch 4000 times. Please explain what I'm doing wrong or tell you about the best solution.
user2022068
source share