简体   繁体   English

从其侦听器中的JComboBox中删除元素

[英]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 谢谢

考虑使用两个JComboBoxAutocompleted JTextField加上JComboBox (而不是你描述的请求),你必须从JTextField获取所有突出显示的Chars(仅创建与过滤Item相同的方法的构造函数)并动态更新ComboBoxModel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM