private void updateTextAlignment() {
    if (myEditorPane == null) return;

    myEditorPane.setBorder(null); // clear border

    int position = getVerticalTextPosition();
    if (position == TOP) {
      return;
    }

    int preferredHeight = myEditorPane.getPreferredSize().height;
    int availableHeight = getHeight();
    if (availableHeight <= preferredHeight) {
      return;
    }

    // since the 'top' value is in real already-scaled pixels, should use swing's EmptyBorder
    //noinspection UseDPIAwareBorders
    myEditorPane.setBorder(new EmptyBorder(position == CENTER ? (availableHeight - preferredHeight + 1) / 2 :
                                           availableHeight - preferredHeight, 0, 0, 0));
  }
private void updateTextAlignment()