Autocomplete in a jTextfield - adapt class

1

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?

    
asked by anonymous 10.11.2014 / 13:32

1 answer

1

Answering your question:

  

I would like to know where I am in positioning the list of   suggestions, because it's popping me up a lot over the textField.

You can make this change in the class:

AutoSuggestor

In method:

showPopUpWindow 

In this line of code:

autoSuggestionPopUpWindow.setMinimumSize(new Dimension(textField.getWidth(), 30));
    
10.12.2014 / 14:52