Im using Swing where I want to populate jList with names of students objects from the HasMap collection. Each student’s key in a Map is the name of that student.
I would prefer that if I add/remove single student from map, then only that student is removed from jList, instead of each time calling createList() method where new whole updated list of students is added to jList. Im not sure how this could be achieved. In my code I have retrieved the keys from Map and added them to the jList as demoList Strings.
Also what is the best way to connect the name/key of student in jList to the actual student's objecst keys in a Map? For example user selects John Scott in jList and after pressing details button the details of that student are retrieved from the HashMap collection. In my solution the name of student the user selects can be captured and then selected name can be found as the key in a collection. Again is there better way to do achieve that?
Map<String, Student> students = new HasMap<>();
Set<String> keyStudent = students.keySet();
DefaultListModel demoList = new DefaultListModel();
public void createList()
{
for (String eachKey: keyStudent)
{
demoList.addElement(eachKey);
}
}