Note that there are some explanatory texts on larger screens.

plurals
  1. POPopulating JList from Hashmap and retriving key
    primarykey
    data
    text
    <p>How can I populate JList from a HashMap but to have only the value displayed in the list?</p> <p>I am populating the list with following code. When I start the application I get list items like {1=Value1}, {2=Value2} etc. I want to display just the value. </p> <p>I am using the HashMap because I need later when I submit the form where JList is to use the keys from values selected for my Insert method and I understood from other examples here that this is done with hashsmap.</p> <pre><code>public void populateListwithCategories(final JList list) { try { DefaultListModel listModel = new DefaultListModel(); List&lt;AdvertisementCategory&gt; advertisementCategories = advertisementCategoryProvider.getAdvertisementCategories(); for (AdvertisementCategory advertisementCategory : advertisementCategories) { int id = advertisementCategory.getId(); String name = advertisementCategory.getName(); advertisementCategory.advertisementMap.put(id, name); listModel.addElement(advertisementCategory.advertisementMap); } list.setModel(listModel); } catch (MalformedURLException ex) { Logger.getLogger(AdvertisementCategoryController.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(AdvertisementCategoryController.class.getName()).log(Level.SEVERE, null, ex); } } </code></pre> <p>This is My AdvertisementCategory model from where I want to export the data to hashmap.</p> <pre><code>public class AdvertisementCategory { private int id; private String name, description; public List&lt;AdvertisementCategory&gt; advertisementCategories; public Map&lt;Object, String&gt; advertisementMap = new HashMap&lt;&gt;(); public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public AdvertisementCategory(int id, String name, String description) { this.id = id; this.name = name; this.description = description; } public AdvertisementCategory(String name, String description) { this.name = name; this.description = description; } public AdvertisementCategory() { } public AdvertisementCategory(int id, String name) { this.id = id; this.name = name; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload