reasons: 是从服务器一次拉取全部不重复的过往的填写记录
public class ComboxKeyAdapter extends KeyAdapter{
public List reasons;
public ComboxKeyAdapter(List reasons){
this.reasons = reasons;
}
@Override
public void keyReleased(KeyEvent e){
ComboBoxEditor editor = comboBox.getEditor();
JTextField textField = (JTextField)editor.getEditorComponent();
List result = new ArrayList();
String objStr = textField.getText();
if(objStr!="" && !objStr.equals("")){
for(PriceChangeReason res : reasons){
if(objStr.equals(res.getMemo())
|| res.getMemo().contains(objStr)
|| res.getMemo().startsWith(objStr)
|| res.getMemo().endsWith(objStr)){
result.add(res);
}
}
String[] memos;
if(result.size() > 0){
comboBox.hidePopup();
comboBox.removeAllItems();
memos = new String[result.size()];
for(int i = 0; i < result.size();i++){
PriceChangeReason reason = result.get(i);
memos[i] = reason.getMemo();
comboBox.addItem(reason.getMemo());
}
comboBox.setSelectedItem(objStr);
comboBox.showPopup();
}
}else{
comboBox.hidePopup();
comboBox.removeAllItems();
for(int i = 0; i < reasons.size();i++){
PriceChangeReason reason = reasons.get(i);
comboBox.addItem(reason.getMemo());
}
comboBox.setSelectedItem("");
comboBox.showPopup();
}
}
}
网友评论