Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swing autocomplete text field / drop down

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 }

like image 926
Pablo Avatar asked Jun 25 '26 07:06

Pablo


2 Answers

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));
like image 93
Erick Robertson Avatar answered Jun 27 '26 20:06

Erick Robertson


GlazedList Not very good, also SwingX support Auto-Complete and easier than "GlazedList". you only writing:

AutoCompleteDecorator.decorate(yourComboBox);
like image 27
Marwen Trabelsi Avatar answered Jun 27 '26 21:06

Marwen Trabelsi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!