Reputation: 3058
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);
}
}
});
Upvotes: 4
Views: 1535
Reputation: 6886
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.
Upvotes: 2
Reputation: 116
shouldn't be difficult. Just take a List where all your search strings are and then do some regex or indexOf stuff or Collections.binarySearch etc. Then draw a list down the text field with all the options. I can write you an example. What type of is the search data?
Upvotes: 0
Reputation: 19443
I don't think there is anything like that in SWT. Widgets in SWT have to correspond to native widgets on all platforms (generally), so implementing something like that would be difficult. One place to look for SWT Widgets that are new or experimental is the Nebula project, but I don't see it there either.
Upvotes: 2