I’m trying to create a GUI to display the content of a database. I’m using a JTable for that. I want a constructor that takes a list of POJOs and eventually column titles. I want also my JTable to be able to return the selected POJO (for example when I doubleclick on a row). Do I really need to create a table model for each POJO or is there a better way?
I’ve made some searchs on similar topics, but I didn’t find any answer that uses a single table model for all POJOs and none of them has a method that returns a POJO.
Here is the description of my database tables and POJOs:
Database tables:
- students (id, firstname, lastname, birthdate, grade_id, phonenumber)
- grades (id, grade)
- authors (id, firstname, lastname, nationality_id)
- nationalities (id, nationality)
- books (id, title, author_id, student_id)
POJOs:
- Grade (int id, String grade)
- Student (int id, String firstname, String lastname, Grade grade)
- Author (int id, String firstname, String lastname, Nationality nationality)
- Nationality (int id, String nationality)
- Book (int id, String title, Author author, Student student)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…