• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with JComboBox additem() method

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dynamically build a user defined series of JComboBoxes via a loop.
During the build i test if a certain condiion is true, if true I add an item to the JcomboBox currently being built.
Problem is that when i add an item, i end up adding the new item to each box, 2 time.
Hopefully fresher eyes can spot my error:
as always, many thanks in advance,
Pete
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see the problem off hand, but you could simplify this loop quite a bit:




Change it to:

I'm sorry that this doesn't answer your question. It should make your code a bit less complicated, though.
 
Peter Simard
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a hunch it may have something to do with how addItem work, but i've not found anything yet...
Thanks for the effort, and thanks for the 'code-cleanup', nice idea,
Regards,
Pete
 
Peter Simard
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a method that was not returning the correct values, so after fixing that I get the correct values, but i still have the problem where every combo-box has a new vlaue added when i call addItem(), not just the one being built at that moment.

Any ideas??
Regards,
pete
 
Peter Simard
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved:
I was using one instance of a Vector to populate all my JComboBoxes, so the changes to that Vector were propagated throughout all the JComboBoxes...
 
reply
    Bookmark Topic Watch Topic
  • New Topic