• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to reflect changes of Data in a JComboBox?  RSS feed

 
Sarone Thach
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
JComboBox has a constructor that takes a Vector. this will be its dataModel.
Say I have created the JComboBox and given it a Vector. If dynmically i add new Data to the Vector, how would I get the JComboBox to update to reflect the changes in data add?
Any ideas?
thanks ,
Sarone
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JComboBox has a method "addItem(Object anObject)", but this will work only if you have a data model that recognizes changes. I believe that the default model doesn't recognize changes. So you have two choices:
1) Write you own class that implements "ComboBoxModel" and use it, or
2) replace the entire data model every time you change the underlying data. This is done via:

Obviously "myComboBox" is your JComboBox instance, and "myData" is your new Vector (or Array) of data.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!