I suggest you add a DocumentChangeListener to your JTextField to monitor inserted / deleted / updated characters:
JTextField textField = new JTextField; textField.addDocumentListener (new DocumentListener() { public void changedUpdate(DocumentEvent e) { } public void removeUpdate(DocumentEvent e) { } public void insertUpdate(DocumentEvent e) { } } );
Take a look at this tutorial .
So I need several functions, at first one is easy: filter the set of lines with the already typed text.
Now that you have the typed text, filter your set of lines. Be careful when choosing an efficient way to store and retrieve rows from your data structure. With lots of lines to sort, this might not be trivial. (I think it will be difficult with an ArrayList if you set the strings if they are quite large.)
But how to show them on the list?
I think you could use JLabel. Alternatively, you can try using JComboBox by implementing your own ComboBoxModel . I do not know if it is always possible to open the combo box.
source share