Mat3 Ответов: 0

Добавление элементов в jlist


How to populate jList by the keys from Map collection? I have added jListCars to a jScrollPanel and now I want to populate jListCars by key Strings from Map. So far I have used demoList that is added to jListCars. However I will need often to add new vehicles and I dont want each time to be adding updated demoList to jListCars. Is there some better way to do it? Also user should be able to select the car in jListCars to get other information about the vehicle.   


Что я уже пробовал:

Map<String, Car> cars = new HasMap<>();     
   
Set<String> keysCar = cars.keySet();
DefaultListModel demoList = new DefaultListModel(); 
     
public void createList()
{
    for (String eachKey: keysCar)
    {      
        demoList.addElement(eachKey);                                       
    } 
                       
    jListCars.add(demoList); ????????

0 Ответов