Watch the video above to understand how to autocomplete jtextfield
Code of set
Set<String> s=new TreeSet<String>();
s.add("unpossible");
s.add("pog");
s.add("steve rogers");
Copy below code in key_released event of jtextfield.
if(evt.getKeyCode()==KeyEvent.VK_BACK_SPACE||evt.getKeyCode()==KeyEvent.VK_DELETE)
{
}
else
{
String to_check=jTextField1.getText();
int to_check_len=to_check.length();
for(String data:s)
{
String check_from_data="";
for(int i=0;i<to_check_len;i++)
{
if(to_check_len<=data.length())
{
check_from_data = check_from_data+data.charAt(i);
}
}
//System.out.print(check_from_data);
if(check_from_data.equals(to_check))
{
//System.out.print("Found");
jTextField1.setText(data);
jTextField1.setSelectionStart(to_check_len);
jTextField1.setSelectionEnd(data.length());
break;
}
}
}
i need it for textArea
ReplyDelete