txtfName = new JTextField();
txtfName.setBorder(null); // <-- this has no effect.
txtfName.addKeyListener(new KeyAdapter() {
@SuppressWarnings("unchecked")
@Override
public void keyReleased(KeyEvent e) {
try {
cboName.removeAllItems();
cboName.setPopupVisible(true);
cboName.showPopup();
String val = txtfName.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();
}
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
String str = (String) cboName.getSelectedItem();
txtfName.setText(str);
}
}
});
txtfName.setBounds(406, 294, 159, 20);
contentPane.add(txtfName);
txtfName.setColumns(10);