1

I have a Java program with a model and a GUI. On my Frame (that implements Observer) I have put a jcombobox with a list of registration from my model (that extends Observable).

When I click on a button add registration the list in my model changed. And than I do

setChanged(); 
notifyObservers();

In my update method I want to make change the values of the jcombobox. I tried with a repaint() or something like that, but my combobox doesn't change. I am sure I go to my update method, but I don't know how I have to change the jcombobox.

Can someone help

mKorbel
  • 109,107
  • 18
  • 130
  • 305
Bigjo
  • 601
  • 2
  • 7
  • 30

1 Answers1

2

Your update() implementation should obtain a reference to the combo's model and either set the selected item or add a new item, as warranted. A PropertyChangeEvent, illustrated here, may be an alternative, as it can include both old and new values.

Community
  • 1
  • 1
trashgod
  • 200,320
  • 28
  • 229
  • 974
  • 2
    Ok thanks that works. I took my comboBox model and used the insertItemAt(args,index) method. – Bigjo Mar 27 '13 at 12:15