【发布时间】:2013-02-04 14:41:28
【问题描述】:
我编写了一个自动完成组合框程序,在该程序中搜索用户在文件中输入的单词。该程序运行良好,但是,combobox editor 在输入内容时不会返回任何内容。我不知道这是为什么.. 这是处理问题的代码块。
// in GUI class constructor
InstantSearchBox = new JComboBox();
InstantSearchBox.setEditable(true);
/*****/
KeyHandler handle = new KeyHandler();
InstantSearchBox.getEditor().getEditorComponent().addKeyListener(handle);
// Keylistener class (KeyPressed method)
try
{
dataTobeSearched = InstantSearchBox.getEditor ().getItem ().toString ();
// the string variable is empty for some reason
System.out.println ("Data to be searched " + dataTobeSearched);
}
catch (NullPointerException e)
{
e.printStackTrace ();
}
问候
【问题讨论】:
-
我怀疑这种方式是否有可能提出一些建议......为了更好的帮助,尽快发布SSCCE,短可运行,可编译,大约
JFrame和JComboBox并带有Items的硬编码值 -
这里有两个答案,不是,从来没有,这种方式不可能在
Editorvs. 中捕获non_finalized KeyEvents。在 Swing 中为Autocompleted funcionalities铺设Document
标签: java string swing jcombobox