Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems with JComboBox additem() method  RSS feed

 
Peter Simard
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!