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 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));
GlazedList Not very good, also SwingX support Auto-Complete and easier than "GlazedList". you only writing:
AutoCompleteDecorator.decorate(yourComboBox);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With