java - Populate ComboBox with one value of the HashMap(Object) -
i have combobox want populate product names. have class called producto has values:
private string name; private string code; private int price;
so created hashmap this:
map(integer, producto) mapproducto=new hashmap<integer, producto>();
i have method populate hashmap:
producto stockproducto=new producto(); stockproducto.setnomproducto("steel bike"); stockproducto.setcodeproducto("bic001"); stockproducto.setprice(190000); getmapproducto().put(1, stockproducto); stockproducto.setnomproducto("aluminium bike"); stockproducto.setcodeproducto("bic002"); stockproducto.setprice(290000); getmapproducto().put(1, stockproducto);
after populate combobox:
iterator iter=getmapproducto().keyset().iterator(); while(iter.hasnext()) { this.cbonomproducto.additem(getmapproducto().get(iter.next())); }
but since receives object of producto type, populates combo weird code, guess memory direction of object. want populate combobox name of product. how can value of object producto?
thanks in advance.
try this
iterator iter=getmapproducto().keyset().iterator(); while(iter.hasnext()) { this.cbonomproducto.additem(getmapproducto().get(iter.next()).getnomproducto()); }
details:
getmapproducto().get(iter.next())
return producto
object can't directly set combobox, have product name object , add combobox.
edit
producto stockproducto=new producto(); stockproducto.setnomproducto("steel bike"); stockproducto.setcodeproducto("bic001"); stockproducto.setprice(190000); getmapproducto().put(1, stockproducto); stockproducto = new producto(); // forgot stockproducto.setnomproducto("aluminium bike"); stockproducto.setcodeproducto("bic002"); stockproducto.setprice(290000); getmapproducto().put(1, stockproducto);
if don't create new producto
same object referenced twice in hashmap
instead of 2 different producto
Comments
Post a Comment