GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes JComboBox.setSelectedItem() doesn't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JComboBox.setSelectedItem() doesn Watch "JComboBox.setSelectedItem() doesn New topic
Author

JComboBox.setSelectedItem() doesn't work

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622





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




What is the mistake here?

kunal
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

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?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jun 05, 2010
Posts: 622
Sorry, my fault

Actually combo box contains String objects, and the value returned by sae.getClassAdmitted() is of String type, i.e "2".
 
GeeCON Prague 2014
 
subject: JComboBox.setSelectedItem() doesn't work