This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Dynamically updating JComboBox contents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamically updating JComboBox contents" Watch "Dynamically updating JComboBox contents" New topic
Author

Dynamically updating JComboBox contents

Sean O'Donnell
Greenhorn

Joined: Dec 27, 2005
Posts: 12
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

Joined: Sep 20, 2005
Posts: 862
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?


bitguru blog
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamically updating JComboBox contents
 
Similar Threads
URLyBird Search Options
JComboBox Mystery!
different JComboBoxes as editors on multiple JTable rows
JScrollPane and JComboBox, loss of drop down
JComboBox Vertical Scrollbar not showing up.