1
I was able to find here a code for autocomplete in a jTextfield. As I am new to programming, I have tried to adapt this code to use in Jtextfields of other classes I have but I haven’t been able to.
I tried to put this part of the code in my jTextfield action but it says that the Autosuggestor class is not published and so I can’t 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 make it public in the Test class which is the one that works with autocomplete but without success. Any hints where to start adjusting this autocomplete to my textFields?
Maybe go through the constructor the textField and the Word List? But how to then adapt in my code?
I’ve already managed to adapt the code as I wanted to now I wonder where I move in the positioning of the suggestion list, because it’s showing me very much on the textField.
– Hugo Machado
If I understand what you said I think you should change this line of code
autoSuggestionPopUpWindow.setMinimumSize(new Dimension(textField.getWidth(), 30));
class:AutoSuggestor
function:showPopUpWindow
– jsantos1991
Yes yes it was that line of code. Thank you !
– Hugo Machado
@jsantos1991 could post as an answer to resolve the topic, no?
– Math