Click here to Skip to main content
15,885,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.   


What I have tried:

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); ????????
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900