开发者

Remove elements from a JComboBox within its listeners

开发者 https://www.devze.com 2023-04-04 17:37 出处:网络
I have a combobox, with certain elements within it, eg:开发者_Go百科 \"abc\", \"pqr\", now when the user types \"a\", I wish to refresh the combobox and remove all its elements and then again add only

I have a combobox, with certain elements within it, eg:开发者_Go百科 "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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消