The problem is that when I enter some character in JComboBox
then it just autoselected, again I enter other text then it replace the first character, so I am not able to type multiple character in JComboBox
(my JComboBox
is editable)...
pleasw help.
private void combo1KeyReleased(java.awt.event.KeyEvent evt)
{
if((evt.getKeyChar() >= '0' && evt.getKeyChar() <= '9')||(evt.getKeyChar() >= 'a' && evt.getKeyChar() <= 'z')||(evt.getKeyChar() >= 'A' && evt.getKeyChar() <= 'Z')||evt.getKeyCode() == KeyEvent.VK_BACK_SPACE)
{
try
{
Connection con=null;
ResultSet rs;
con=LoginConnection.getConnection();
String srch="";
if(con!=null)
{
srch=(String)combo1.getEditor().getItem();
System.out.println("value to search:"+srch);
String s="select name from supplier where name like '%"+srch+"%' order by name";
PreparedStatement pst=con.prepareStatement(s,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=pst.executeQuery();
int itemCount = combo1.getItemCount();
System.out.println("no of value="+itemCount);
for(int i=0;i<itemCount;i++){ //removing items
combo1.removeItemAt(0);
}
if(!rs.next())
{
System.out.println("----------------------No Data Found");
}
else
{
rs.beforeFirst();
while(rs.next())
{
combo1.addItem(rs.getString(1)); // addind item
System.out.println("while value is:"+rs.getString(1));
}
}
combo1.getEditor().setItem(srch);// adding item in field which i have fetched using getItem method
combo1.showPopup();
}
}
catch(Exception e)
{
System.out.println("ex:"+e);
}
}
}