【发布时间】:2014-01-18 16:24:47
【问题描述】:
我只是想在我按下回车键之前不要将项目添加到 JList 中,因为我创建了一个类似 Google 的搜索框。我认为是组合框没有“读取”“输入”键。
public void count(){
try{
String sql2 = "select count(*) from workers_info";
stmt = conn.prepareStatement(sql2);
rs=stmt.executeQuery();
while(rs.next()){
String x = rs.getString("count(*)");
z = Integer.parseInt(x);
}
auto = new String[z];
}
catch(SQLException | NumberFormatException e){
}
}
public void cB(){
try{
String sql = "Select concat(first_name, ' ',last_name) as full_name from workers_info";
stmt = conn.prepareStatement(sql);
rs=stmt.executeQuery();
while(rs.next()){
String name = rs.getString("full_name");
auto[i] = name;
i++;
}
AutoCompleteSupport a = AutoCompleteSupport.install(comboSearch, GlazedLists.eventListOf(auto));
a.setStrict(false);
comboSearch.isEditable();
}
catch(SQLException e){
}
}
//this actually is my main concern..why it cant detect when i hit "enter" key?
private void comboSearchKeyPressed(java.awt.event.KeyEvent evt) {
String s1 = (String)comboSearch.getSelectedItem();
if(evt.getKeyCode()==KeyEvent.VK_ENTER){
model.addElement(s1);
workerList.setModel(model);
comboSearch.setSelectedItem(null);
}
}
【问题讨论】:
标签: java swing jcombobox jlist