views:

52

answers:

2

Hi,

We need an autocomplete component for swing, the problem with the one in jdesktop/SwingX is that we have to use a combo box and after each key stroke it simply scrolls down to the nearest match but the combo still holds the 25.000 elements. It doesn't show the 4 or 5 that are the closest match together because they can be in different places of the list. We don't want to display a list with the 25000 either...

Is there anything similar to the JSF autocomplete or the one in google main page? What we need is a component which asks our interface something like

public List getOptions(String typedSoFar) { //here we return the 5 matching ones according to our criteria and simply offers the //user those five }

A: 

I have not used SwingX and know nothing about their implementation. The best idea would probably be to extend the SwingX Autocomplete class. Instead of using the Autocomplete class directly, create a proprietary class extendig the Autocomplete class and override the getOptions() method:

class OurOwnAutocomplete extending swingx.*.*.autocomplete {

    private List getOptions(String typedSoFar) { // 

    // logic 

   }
matiasf
There is no such method getOptions in the Autocomplete from swingX
Pablo
A: 

A really easy way to do this is to use the GlazedList implementation of auto-completion. It's very easy to get up and running. You can find it here:

http://publicobject.com/glazedlists/

You can install the auto-complete on a JComboBox with only one line of Glazed code, like this:

JComboBox comboBox = new JComboBox();
Object[] elements = new Object[] {"Cat", "Dog", "Lion", "Mouse"};
AutoCompleteSupport.install(comboBox, GlazedLists.eventListOf(elements));
Erick Robertson