txtfCustomer = new JTextField();
txtfCustomer.setFont(new Font("Times New Roman", Font.BOLD, 14));
txtfCustomer.addKeyListener(new KeyAdapter() {
@SuppressWarnings("unchecked")
@Override
public void keyReleased(KeyEvent e) {
try {
cboName.removeAllItems();
String val = txtfCustomer.getText().trim();
if (!val.equals("")) {
String query = "select distinct CUSTOMER from TBL_DRUG_123 where CUSTOMER like '%" + val
+ "%' ";
Statement pst = conn.createStatement();
ResultSet rs = pst.executeQuery(query);
while (rs.next()) {
cboName.addItem(rs.getString("CUSTOMER"));
}
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
@SuppressWarnings("deprecation")
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
String str = (String) cboName.getSelectedItem();
txtfCustomer.setText(str);
cboName.setVisible(false);
cboName.setPopupVisible(false);
cboName.hidePopup();
cboName.hide();
txtfRate.requestFocus();
txtfRate.setBackground(Color.CYAN);
if (e.getKeyCode() == KeyEvent.VK_DOWN) {
//WHAT IS THE CODE HERE ??????
if (e.getKeyCode() == KeyEvent.VK_UP) {
//WHAT IS THE CODE HERE ??????
}
}
}
}
public void keyTyped(KeyEvent e) {
contentPane.add(cboName);
cboName.setVisible(true);
cboName.setPopupVisible(true);
cboName.showPopup();
}
});
txtfCustomer.setColumns(10);
txtfCustomer.setBorder(null);
txtfCustomer.setBounds(96, 89, 109, 26);
contentPane.add(txtfCustomer);
cboName = new JComboBox();
cboName.setFont(new Font("Times New Roman", Font.BOLD, 14));
cboName.setSelectedItem("");
AutoCompleteDecorator.decorate(cboName);
cboName.setBounds(220, 278, 159, 22);
//contentPane.add(cboName);