I want a drop down ComboBox like Google Search (i.e. when we type one letter then the elements starting with that letter are displayed). When the drop down list appears, then we can select one of word as our text box value.
Can I do this in SWT?
comboLabel.addKeyListener(new KeyListener()
{
@Override
public void keyReleased(KeyEvent e)
{
ArrayList<String> listElements = new ArrayList<String>();
// on pressing down arrow list gets expanded i.e list drops down
if(e.keyCode == 16777218)
{
comboLabel.setListVisible(true);
}
// if key pressed is only a number of charecter or space.
else if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 97 && e.keyCode <= 122) || e.keyCode == 32)
{
// for removing all previously assigned labels
comboLabel.remove(0,comboLabel.getItemCount()-1);
listElements = labels.getLabels(comboLabel.getText());
}
for (int i=0; i<listElements.size();i++)
{
comboLabel.add(listElements.get(i),i);
}
}
});
What you are referring to is an auto-suggest ComboBox. As far as I know, it's not available in any Java standard widget library. However, a lot of people have built their own auto-suggest component. Here's a good example with both source and an executable ".jnlp" extension.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments