I was able to find here a code to autocomplete a jTextfield. As I am new to programming, I have already tried to adapt this code to use in JTextfields of other classes that I have but have not yet achieved.
I tried to put this part of the code in the action of my jTextfield but it says that the AutoSuggestor class is not public and so I can not use it in my package:
private void fActionPerformed(java.awt.event.ActionEvent evt) {
_global.AutoSuggestor autoSuggestor = new _global.AutoSuggestor(f, frame, null, Color.WHITE.brighter(), Color.BLUE, Color.RED, 0.75f) {
@Override
boolean wordTyped(String typedWord) {
//create list for dictionary this in your case might be done via calling a method which queries db and returns results as arraylist
ArrayList<String> words = new ArrayList<>();
words.add("hello");
words.add("heritage");
words.add("happiness");
words.add("goodbye");
words.add("cruel");
words.add("car");
words.add("war");
words.add("will");
words.add("world");
words.add("wall");
setDictionary(words);
//addToDictionary("bye");//adds a single word
return super.wordTyped(typedWord);//now call super to check for any matches against newest dictionary
}
};
}
I have tried to put it publicly in the Test class which is the one that works the autocomplete but without success. Any tips on where to start adjusting this autocomplete to my textFields?
Maybe pass through the constructor the textField and Word List? But how do I later adapt it in my code?