如何在文本字段内键入时列出建议 [英] How to list suggestions to when typing inside the text field
问题描述
在我的 Java Swing 应用程序中,我需要用相同的初始值显示所有可能的现有条目用户在文本字段中键入时的字符.假设用户在文本字段中键入字母A",应该是美国"和非洲"国家/地区的建议.这样用户就可以从列表中选择一个.国家/地区列表位于我的数据库中.我知道如何从数据库中检索数据.但我不知道如何列出它们以及我应该使用哪些组件来实现.任何人都可以指导我吗?或者如果你能提供一个例子,那就太好了.
Hi in my Java swing application I need to show all possible existing entries with same initial characters while user typing in a text field. Lets say user type letter 'A' in a text field which should be a country 'America' and 'Africa' would be suggestions. So that user can select one from the list. Country list resides in my database. I know how to retrieve data from DB. But I don't know how to list them and which components I should use to achieve. Can any one guide me? Or if you can provide an example, that would be great.
推荐答案
您可以使用 来自 SwingX 的自动完成包.如果您需要更多现实生活中的示例,请谷歌搜索swingx 自动完成",但最简单的方法是创建一个 JComboBox
并调用 AutoCompleteDecorator.decorate(comboBox);
就可以了.
You could use the autocomplete package from SwingX. Google for "swingx autocomplete" if you need more real life examples, but the simplest way is creating a JComboBox
and calling
AutoCompleteDecorator.decorate(comboBox);
on it.
这篇关于如何在文本字段内键入时列出建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!