• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox.setSelectedItem() doesn't work

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator





But the code following this, doesn't get those values selected in the JComboBox




What is the mistake here?
 
Rob Spoor
Sheriff
Pie
Posts: 20493
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the objects you want to set as selected items are a) members of the combo boxes' contents, and b) are equal to a member of those combo boxes, as returned by the equals(Object) method?
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Rob.



sae.getClassAdmitted() returns '2', which is in the combo boxes' contents.

b) are equal to a member of those combo boxes, as returned by the equals(Object) method?

I didn't understood this
 
Paul Clapham
Sheriff
Pie
Posts: 20729
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean to say that sae.getClassAdmitted() returns a char value '2' and that the combo box contains Character objects, one of which contains that value? Or did you mean something else when you put the single quotes around the 2?
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, my fault

Actually combo box contains String objects, and the value returned by sae.getClassAdmitted() is of String type, i.e "2".
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic