This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hello I have a combobox where in initially i populate the combobox by passing a vector which contains nearly 10000 values.At a later stage i want to re-populate the combo box,but it does not. 1)vAllSwitch-- is the actual vector containig the data 2) initally i populate by Vector vAllSwitchhd = new Vector(); vAllSwitchhd = (Vector)vAllSwitch.clone(); cbxMTSwitch = new JComboBox(vAllSwitchhd);
3)Vector vAllSwitch1 = new Vector(); vAllSwitch1 = (Vector)vAllSwitch.clone(); cbxMTSwitch = new JComboBox(vAllSwitch1); after step 3 the data is not populated in combobox,but when i display the value of vector it displays. anny suggestion pl Regards, Johnson
Well, if I decifered your code correctly, it appears that you are cloning 1 vector and then placing that vector in the combobox two different times. Now, my first question would be do the values of that vector change so that you know for sure it is not working? Second question, Are you adding values to the combobox or are you completely replacing all the values with new values? If you answer yes to the second question, here is what I would do. I would do a cbxMTSwitch.removeAllItems() first, and then add your Vector back in. However, if the first is true, I ask again how do you know it is not working? Sometimes in SWING or AWT you need to call the revalidate() or rePaint() method to actually see component changes.
Hello, Now as per your queries The value of vector do not change.I am able to display the vector values but when i try to add it does not add. I had tried cbxMTSwitch.removeAllItems() in this case it removes but then cobbobox is empty. My component do not cahnge but problem is how to add values to combobox second time.If i loop throgh the vector and add the value is added,but i want to add it in one go just pass the vector in constructor. Regards, E Johnson
of course removeAllElements makes your combobox empty. That is what it does. If you have your Combobox filled with items from a Vector, then you try and fill that vector again with the same elements, you are going to have two (2) of every element. You must remove all the elements before adding the elements back in.
Joined: Apr 20, 2002
but my problem of why the elements are not getting added to combobox is not yet addresssed. if i remove all item before adding then i get a blank combobox else nothing is added to conmo box the previous value is retained. Johnson
10000 values in a JComboBox? Maybe it is time to rethink the design some. That might be a bit too much. Adding and removing elements from JComboBox is not a major thing. Have you went throught the Sun tutorial? Have you searched in this forum? What are you trying to accomplish that the combo box gets filled with 10000 elements?
Joined: Apr 20, 2002
Hi, No one is trying to adress the problem why i am not able to add elements into combobox.Once i am able to add but when trying to add next time it does not get added. Design is proper, no question of changing it. if any one can suggest. Pl try to address the core problem. johnson