Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically updating JComboBox contents

 
Sean O'Donnell
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all-
I have an application with multiple JComboBoxes. The contents of the JComboBoxes is a static collection member (so they all have the same values available). The problem I'm having is after I add an item to the static collection, when you pulldown some of the other JComboBoxes, there is nothing displayed at first, but you can click in it and the last value in the list is displayed, and when you pull the JComboBox down a second time, the right values are then displayed. I've tried a repaint() after the add, doesn't work. Also, this problem seems to be random, it doesn't happen to all the JComboBoxes all the time, just some of them some of the time. Has anyone has a problem similar to this before?

Thanks.
Sean
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't tell from what you've said here if you're doing this a right way or a wrong way.

When you add an item to your static collection, is it also being added to the ComboBoxModels? If so, are the ComboBoxModels firing ListDataEvents to notify the JComboBoxes?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like you're using the JCombBox(Vector) constructor,
then adding items to the Vector.

Doesn't work like that.

If you want the combos to be the same, set their models the same,
then add items to the model.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic