Point (@NotNull LightweightHint hint, @NotNull Editor editor, @NotNull VisualPosition pos1, @NotNull VisualPosition pos2, @PositionFlags short constraint, boolean showByBalloon) { if (ApplicationManager.getApplication().isHeadlessEnvironment()) return new Point(); Point p = _getHintPosition(hint, editor, pos1, pos2, constraint, showByBalloon); JComponent externalComponent = getExternalComponent(editor); Dimension hintSize = hint.getComponent().getPreferredSize(); if (constraint == ABOVE) { if (p.y < 0) { Point p1 = _getHintPosition(hint, editor, pos1, pos2, UNDER, showByBalloon); if (p1.y + hintSize.height <= externalComponent.getSize().height) { return p1; } } } else if (constraint == UNDER) { if (p.y + hintSize.height > externalComponent.getSize().height) { Point p1 = _getHintPosition(hint, editor, pos1, pos2, ABOVE, showByBalloon); if (p1.y >= 0) { return p1; } } } return p; }