java - JComboBox getSelectedItem is return correct values but .equals not working -


so have jcombobox, able select each of items within fine. in system.out.print correct values, though when preform .equals on string "create map" not caught if control statement. missing obvious here?

mapselectionbox = new jcombobox();     mapselectionbox.seteditable(false);     map amapvalues;     for(entry<string, map> obj : runinfo.gethashmap().entryset()){         amapvalues = obj.getvalue();         mapselectionbox.additem(obj.getkey());     }     object addnewmap = new object(){public string tostring(){ return "create map"; } };      mapselectionbox.additem(addnewmap);  mapselectionbox.addactionlistener(new actionlistener(){         public void actionperformed(actionevent e) {             if(mapselectionbox.getselecteditem().equals("create map")){                 xcoordinatestextfield = new jtextfield();                 xcoordinatestextfield.seteditable(true);                 windowcontainer.add(xcoordinatestextfield, "6, 4, right, default");                 system.out.println("test");             }else{                 system.out.println(mapselectionbox.getselecteditem());             }         }     }); 

so starting think is evaluating getselecteditem object , not string have stored in hash map. case?

edit: figured out. changed in above code. comment.

string selecteditem = mapselectionbox.getselecteditem().tostring();             if(selecteditem.equalsignorecase("create map")) 

the problem is, items in combo box not strings. trying compare object using mapselectionbox.getselecteditem().equals("create map") isn't going work, equals won't use tostring method of object internal comparisons of state of object instead.

try using like...

mapselectionbox.getselecteditem().tostring().equalsignorecase("create map") 

...instead...


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -