File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JcomboBox duplicates problem

 
ishiro moh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have two JComboBoxs, the first one is filled from database, the second one is filled after user's choice on the first comboBox.
Once a choice in second comboBox is done, some JLabels are filled from database.

The problem is that when I select an item in the first combobox and then I change the choice thr first item is always present and the second is added with dupplicates.




Thanks and sorry for my english.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like you need to specify
itemEvent's getStateChange()
 
ishiro moh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply Michael, i tried that but still the same problem, there is always duplicates in addition to the new items added.

 
ishiro moh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried removeAllItems on the comboBox, it worked but the second comboBox is giving only one items even if there is more.
if i remove the itemListener on the second comboBox it works perfectly the problem is then here but i just can't figure out whats wrong with it:

 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all your code that looks that looks like this (see indicated lines)

change to this
 
ishiro moh
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your time Michael,
I still have the one item shown issue

 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
comboBox1's listener fires twice as there's no ItemEvent.SELECTED separation,
and comboBox2's listener will fire as soon as you change the model, which changes
the selection (would be same for the first addItem of your original posted code).

probably easiest way would be an ItemListener class, instead of the anonymous class.
so instead of

it would go something like this

now, in comboBox1's listener:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic