[英]Remove elements from a JComboBox within its listeners
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. 我有一个组合框,其中包含某些元素,例如:“abc”,“pqr”,现在当用户键入“a”时,我希望刷新组合框并删除其所有元素,然后再次添加那些启动的元素用户字符串。 (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 我尝试在“addCaretListener”中修改其元素,但它抛出“java.lang.IllegalStateException:尝试在通知中变异”异常
Is there a specific way to implement this? 有没有具体的方法来实现这个?
Thanks 谢谢
考虑使用两个JComboBox或Autocompleted JTextField加上JComboBox (而不是你描述的请求),你必须从JTextField获取所有突出显示的Chars(仅创建与过滤Item相同的方法的构造函数)并动态更新ComboBoxModel
I think you create the AutoComplete combo see this example 我认为您创建了自动完成组合,请参阅此示例
http://snippets.dzone.com/posts/show/7633 http://snippets.dzone.com/posts/show/7633
or see this post 或者看这篇文章
Filter Combobox Data in Java 用Java过滤Combobox数据
http://forums.devshed.com/delphi-programming-90/how-to-filter-combobox-items-on-onchangeevent-251852.html http://forums.devshed.com/delphi-programming-90/how-to-filter-combobox-items-on-onchangeevent-251852.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.