JTextField 自动完成 [英] JTextField AutoComplete

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

问题描述

您好:如何为 JTextField 添加自动完成字符串,从 Jtable 列中获取自动完成列表.

Hello: How to add AutoComplete String for JTextField, getting auto complte list from Jtable column.

JTextField textfield = new JTextField();
JTable table =new JTable();

推荐答案

SwingX 库有一个非常方便的 AutoCompleteDecorator功能.

The SwingX library has a very handy AutoCompleteDecorator function.

假设您将 JTable 列的值复制到名为 validValues 的 ArrayList 中.您现在需要在 JTextField myTextField 上自动完成以下代码:

Say you copy the values of your JTable column into an ArrayList called validValues. All you now need for autocompletion on the JTextField myTextField is the following code:

AutoCompleteDecorator.decorate(myTextField, validValues, true);

第三个参数告诉自动完成装饰器您是否需要严格匹配,即是否允许用户输入 JTable 列中的值以外的值.

The third argument tells the autocomplete decorator whether you want strict matching, i.e. whether the user is allowed to enter values other than the ones in your JTable column or not.

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

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