File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Dynamically updating JComboBox contents" Watch "Dynamically updating JComboBox contents" New topic

Dynamically updating JComboBox contents

Sean O'Donnell

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?

Brian Cole
Ranch Hand

Joined: Sep 20, 2005
Posts: 878
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:
subject: Dynamically updating JComboBox contents
jQuery in Action, 3rd edition