JComboBox -- Item is not in the list????????

Reply

Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

JComboBox -- Item is not in the list????????

 
0
  #1
Jul 6th, 2005
I have a "dynamic" JComboBox. What I mean by that is items are removed and added on "the fly".

The getSelectedIndex() is returning -1 when an item is selected. I looked this up and it indicates the selected item is not in the list....What in the world does that mean? The item was added to the ComboBox.

One more thing, the getItemCount() does return the correct number of items..So I don't know why I can't get the selected item or get the selected index.


So, can anyone help me with this?


By the way, I've tried adding a revalidate call but that didn't work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 57
Reputation: Easter Bunny is an unknown quantity at this point 
Solved Threads: 1
Easter Bunny's Avatar
Easter Bunny Easter Bunny is offline Offline
Junior Poster in Training

Re: JComboBox -- Item is not in the list????????

 
0
  #2
Jul 7th, 2005
try getting the model of the combobox and then getting the selected item? i'll check my stuff and see what i do.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 57
Reputation: Easter Bunny is an unknown quantity at this point 
Solved Threads: 1
Easter Bunny's Avatar
Easter Bunny Easter Bunny is offline Offline
Junior Poster in Training

Re: JComboBox -- Item is not in the list????????

 
0
  #3
Jul 7th, 2005
by the way, what does your code for that look like? can't think of anything i did that used comboboxes. did use jlists, but i reckon they should sorta be the same.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 45
Reputation: cheenu78 is an unknown quantity at this point 
Solved Threads: 0
cheenu78's Avatar
cheenu78 cheenu78 is offline Offline
Light Poster

Re: JComboBox -- Item is not in the list????????

 
0
  #4
Jul 7th, 2005
I haven't faced this problem, but there can be one more problem related. If you add two or more same string strings (str1.equals(str2)). Then the getSelectedItem will return the index of the first item which matches the (str1.equals(str2)) criteria.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: JComboBox -- Item is not in the list????????

 
0
  #5
Jul 7th, 2005
Ok, I've changed what I was doing to JList and that worked out fine. Thank you both for helping me. I'll give rep to you guys for your help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC