if (caret != null)
if (caret != null && textComponent.hasFocus())
  protected void paintSafely(Graphics g)  {    Caret caret = textComponent.getCaret();    Highlighter highlighter = textComponent.getHighlighter();        if (textComponent.isOpaque())      paintBackground(g);        if (highlighter != null	&& textComponent.getSelectionStart() != textComponent.getSelectionEnd())      highlighter.paint(g);    rootView.paint(g, getVisibleEditorRect());    if (caret != null)      caret.paint(g);  }