code: public void addText(final String text, final Style style) {
      try {
        SwingUtilities.invokeAndWait(new Runnable() {
          public void run() {
            try {
              doc.insertString(index, text, style);
              index = index + text.length();
              invalidate();
              repaint();
            }
            catch (BadLocationException e) {
              e.printStackTrace();
            }
          }
        });
      }
      catch (InterruptedException e) {
        e.printStackTrace();
      }
      catch (InvocationTargetException e) {
        e.printStackTrace();
      }
  	}
docs: *
  Adds the text synchronously. Do not call from the Event thread. Use a
  working thread.
  
  @param text
  @param style
  @throws InvocationTargetException
  @throws InterruptedException