JTextField 中的下拉列表 [英] drop down list within JTextField

查看:44
本文介绍了JTextField 中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,当我在文本字段中输入一些字母时,应该从我的数据库中选取相关项目并显示为下拉列表.例如:我在文本字段中输入了J",在我的数据库中有诸如 {"Juby','Jaz','Jasmine','Joggy'....}论文名称应显示为列表.这样我就可以从他们中选择一个.等等,其他字母也是如此.awt 中是否有任何预定义的控件?谢谢

I wnt that when i enter some letter in the textfield then the related items should be picked up from my database and should appear as a drop down list. For Example: I typed 'J' in text Field, in my database is having names such as {"Juby','Jaz','Jasmine','Joggy'....} Theses names should appear as a list. So that i could select one from them.and so on for other leters as well. Is there any predefined control in awt?? Thnx

推荐答案

为什么不直接使用 JComboBox?默认情况下,当用户在只读组合框中键入按键并且组合框中的项目以键入的按键开头时,组合框将选择该项目.

Why not just use a JComboBox? By default, when the user types a keystroke in a read-only combobox and an item in the combobox starts with the typed keystroke, the combobox will select that item.

或者您可以使用 setEditable(true) 将 JComboBox 设置为可编辑,并使用 KeySelectionManager.该链接解释了如何通过多次击键在 JComboBox 组件中选择一个项目.

Or you could set the JComboBox to be editable using setEditable(true), and use a KeySelectionManager. The link explains selecting an item in a JComboBox component with multiple keystrokes.

这篇关于JTextField 中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆