private static int getBorder(@NotNull JEditorPane editorPane, boolean top) {
    try {
      Rectangle bounds = editorPane.getBounds();
      if (bounds.width <= 0 || bounds.height <= 0) {
        editorPane.setSize(editorPane.getPreferredSize());
      }

      Rectangle r = editorPane.modelToView(top ? editorPane.getDocument().getLength() - 1 : 3);
      if (r != null) {
        if (top) {
          if (r.y + r.height == editorPane.getHeight()) {
            return 10;
          }
        }
        else if (r.y == 0) {
          return 10;
        }
      }
    }
    catch (BadLocationException ignore) {
    }
    return 0;
  }
private static int getBorder(@NotNull JEditorPane editorPane, boolean top)