RelativePoint (@NotNull Editor editor) { RelativePoint preferredLocation = JBPopupFactory.getInstance().guessBestPopupLocation(editor); Dimension targetSize = getSizeForPositioning(); Point preferredPoint = preferredLocation.getScreenPoint(); Point result = getLocationAboveEditorLineIfPopupIsClippedAtTheBottom(preferredPoint, targetSize, editor); if (myLocateWithinScreen) { Rectangle rectangle = new Rectangle(result, targetSize); Rectangle screen = ScreenUtil.getScreenRectangle(preferredPoint); ScreenUtil.moveToFit(rectangle, screen, null); result = rectangle.getLocation(); } return toRelativePoint(result, preferredLocation.getComponent()); }