Search code examples
javaswinguser-interfacejcombobox

Changing the contents of a JComboBox during runtime


Alright so I'm trying to create a combo box that will update it's contents during runtime except I have no clue how to do this without receiving a bunch of errors. Is there some sort of method that I can use in order to accomplish this? For example, I have a vector that might start out with the name in drawers 1 and 2 be hi and bye. Then during runtime the program will change drawer one and two to eggs, sausage and add a third drawer with the name being computer. How can I go about changing the name on a JComboBox during runtime?


Solution

  • You want to clear the combobox of all entries using removeAllItems(), then re-add the items from the Vector using addItem().