1

I have a combobox, with certain elements within it, eg: "abc", "pqr", now when the user types "a", I wish to refresh the combobox and remove all its elements and then again add only those elements which start with the user string. (These elements are stored in a array)

I tried in to modify its elements in "addCaretListener" but it throws "java.lang.IllegalStateException: Attempt to mutate in notification" Exception

Is there a specific way to implement this?

Thanks

Akash
  • 4,956
  • 11
  • 42
  • 70

2 Answers2

2

consider using two JComboBoxes or Autocompleted JTextField plus JComboBox (instead of your described request), there you have to get all highlighted Chars ( create only contructor to the same method as filtering Item(s) ) from JTextField and dynamically update ComboBoxModel

Community
  • 1
  • 1
mKorbel
  • 109,525
  • 20
  • 134
  • 319
2

I think you create the AutoComplete combo see this example

http://snippets.dzone.com/posts/show/7633

or see this post

Filter Combobox Data in Java

http://forums.devshed.com/delphi-programming-90/how-to-filter-combobox-items-on-onchangeevent-251852.html

Community
  • 1
  • 1
Pratik
  • 30,639
  • 18
  • 84
  • 159