public static <T> void decorate(final JTextComponent textComponent,
                                  SuggestionSource<T> suggestionSource,
                                  SuggestionRenderer<T> suggestionRenderer,
                                  SelectionListener<T> selectionListener,
                                  boolean clearFocusAfterSelection) {

    Document document = textComponent.getDocument();
    SuggestionDocumentListener<? extends T> listener = new SuggestionDocumentListener<>(textComponent, suggestionSource, suggestionRenderer, selectionListener);
    document.addDocumentListener(listener);
    if (clearFocusAfterSelection) {
      textComponent.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
          //do not select all on OSX after suggestion is selected
          if (e.getOppositeComponent() == null) {
            clearTextFieldSelectionAsync(textComponent);
          }
        }
      });
    }
  }
Add popup with suggestion to text component
@param textComponent  text component
@param suggestionSource source of suggestions
@param suggestionRenderer renderer for suggestions
@param selectionListener suggestion listener to be executed after suggestion is selected
@param clearFocusAfterSelection true if text selection should be removed and caret set to end of text after selecting suggestion
@param <T> Suggestion type
olv-gui/src/main/java/pl/otros/swing/suggest/SuggestDecorator.java