code: protected void substituteText(JTextComponent component, String toAdd) {
      String text = completionText;
      if (toAdd != null) {
        text += toAdd;
      }
      try {
        StyledDocument doc = (StyledDocument)component.getDocument();
        //Here we remove the characters starting at the start offset
        //and ending at the point where the caret is currently found:
        doc.remove(dotOffset, caretOffset - dotOffset);
        doc.insertString(dotOffset, text, null);
        Completion.get().hideAll();
      }
      catch (BadLocationException ex) {
        Exceptions.printStackTrace(ex);
      }
    }
docs: Substitutes the text inside the component.
  
  @param component
  @param toAdd optional text which is appended to the completion text