Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for a Combo(Viewer) in SWT/JFace which supports autocomplete

I'm looking for a Combo(Viewer) in SWT/JFace which supports autocomplete / type-ahead, i.e. the user can enter a couple of characters and the drop down list should show all matching elements.

like image 761
Aaron Digulla Avatar asked Jul 01 '09 14:07

Aaron Digulla


3 Answers

You can also check out the org.eclipse.jface.fieldassist.AutoCompleteField class. It's not a combo, just a text field, but it adds auto complete functionality as if it were a combo very easily. You can do something as simple as this:

Text textField = new Text(parentComposite, SWT.BORDER);
new AutoCompleteField(textField, new TextContentAdapter(), new String[] 
    {"autocomplete option 1", "autocomplete option 2"});
like image 59
thehiatus Avatar answered Nov 16 '22 22:11

thehiatus


I don't think there is anything like this built into either Combo or ComboViewer.

As thehiatus suggests org.eclipse.jface.fieldassist.AutoCompleteField is probably the best place to look for this, however, there is support for Combos:

new AutoCompleteField(combo, new ComboContentAdapter(), new String[] 
    {"item0", "item1"});
like image 7
pgkelley Avatar answered Nov 16 '22 22:11

pgkelley


You may be interested in Eclipse's "Content Assist" feature. You can see it in action when using the Eclipse IDE's Java editor. As you edit source code, you will sometimes see a drop-down menu with phrases that complete what you were typing. (Note that you can press Ctrl+Space to force the drop-down menu to be displayed.)

You can implement this in your own SWT/JFace application as well. The "Java Developer's Guide to Eclipse" has an sample application that implements Content Assist. The sample application is a SQL editor, and it is described in Chapter 26, "Building a Custom Text Editor with JFace Text." There's actually an online overview of the chapter here. The sample SQL editor project, com.ibm.jdg2e.editor.jfacetext.sql, can be found here.

On the other hand, if you want to create your own Combo widget and auto-populate it based on input that is being entered, then this might not be very applicable. I'm thinking the org.eclipse.jface.viewers.ComboViewer might be helpful (though I'm not positive).

like image 3
bporter Avatar answered Nov 16 '22 22:11

bporter