在 JComboBox 上实现 AutoCompleteDecorate
对于那些熟悉 SwingX 的 AutoCompleteDecorator 的人,我有一个关于处理 JComboBox 的弹出可见性的问题。我在当前项目中使用了 AutoCompleteDecorate.decorate(JComboBox 组合框) ,我在之前的帖子中已经提到过,我遇到的问题是当用户键入与任何组合框都不匹配的关键字时项目,弹出窗口仍然可见。为了方便用户,如果输入的关键字与任何组合框项目都不匹配,我想隐藏组合框的弹出窗口。
For those who are familiar with SwingX's AutoCompleteDecorator
, I have a question regarding handling of JComboBox
's Popup Visibility. I used AutoCompleteDecorate.decorate(JComboBox combobox)
in my current project which I already mentioned in my previous posts, the problem I encountered is when ever the user type a keyword that doesn't match any of the combobox items, the popup remains visible. For the convenience of the users, I would like to hide combobox's popup if the keyword typed doesn't match any of combobox items.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要自动完成功能,但又不想弹出窗口(特别是,正如您提到的,当输入的文本与任何项目都不匹配时),您可能想尝试开源 JIDE 公共层。它有一个非常有用的(我自己经常使用它)自动完成功能,您可以将其应用于
JComboBox
es、JTextField
s 等。您可以看到 Java Web Start通过单击上页上的“RUN IT”链接或单击 这里。导航至
进行尝试。您还可以通过单击浏览源代码来查看源代码。
您可以启用/禁用严格标志,以防止/允许用户输入与项目不匹配的文本。
然而,据我测试,JIDE 具有自动完成功能的组合框也存在“问题”,即即使未找到匹配项,也会使弹出窗口保持打开状态,但我在这里建议尝试使用没有弹出窗口的自动完成文本字段全部(它们会自动完成,突出显示您没有手动输入的匹配文本部分)。
If you want the autocompletion feature, but you don't want to have a popup in the way (especially, as you mention, when entered text doesn't match any item) you might like to try the opensource JIDE Common Layer. It has a very useful (I use it a lot myself) autocompletion feature that you can apply to
JComboBox
es,JTextField
s, etc..You can see a Java Web Start overview of the components by clicking on the "RUN IT" link on the above page, or by clicking here. Navigate to
to try it out. You can also see the source code by clicking on Browse Source Code.
You can enable/disable a strict flag in order to prevent/allow user to enter text not matched with items.
However, as far as I have tested, JIDE's combo boxes with autocompletion also have the "issue" that keep their popup open even if no match is found, but what I'm suggesting here is to try an autocompleting textfield which has no popup at all (they autocomplete in place, highlighting the part of the matched text that you didn't manually type-in).