从 JComboBox 的侦听器中删除元素
我有一个组合框,其中包含某些元素,例如:“abc”,“pqr”,现在当用户键入“a”时,我希望刷新组合框并删除其所有元素,然后再次仅添加那些开始的元素与用户字符串。 (这些元素存储在数组中)
我尝试修改“addCaretListener”中的元素,但它抛出“java.lang.IllegalStateException:尝试在通知中进行变异”异常
是否有特定的方法来实现此目的?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑使用两个 JComboBoxes 或 自动完成的 JTextField 加 JComboBox (而不是您描述的请求),您必须从中获取所有突出显示的字符(仅创建与过滤项目相同的方法的构造函数) JTextField 并动态更新ComboBoxModel
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
我认为您创建了自动完成组合,请参阅此示例
http://snippets.dzone.com/posts/ show/7633
或查看这篇文章
过滤器Java 中的组合框数据
http://forums.devshed.com/delphi-programming-90/how-to-filter-combobox-items-on-onchangeevent-251852.html
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