RelativePoint (@NotNull Balloon balloon) { FindResult cursor = mySearchResults.getCursor(); if (cursor == null) return null; final TextRange cur = cursor; int startOffset = cur.getStartOffset(); int endOffset = cur.getEndOffset(); if (endOffset > myEditor.getDocument().getTextLength()) { if (!balloon.isDisposed()) { requestBalloonHiding(balloon); } return null; } if (!SearchResults.insideVisibleArea(myEditor, cur)) { requestBalloonHiding(balloon); removeVisibleAreaListener(); myVisibleAreaListener = e -> { if (SearchResults.insideVisibleArea(myEditor, cur)) showReplacementPreview(); }; myEditor.getScrollingModel().addVisibleAreaListener(myVisibleAreaListener); } Point startPoint = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(startOffset)); Point endPoint = myEditor.visualPositionToXY(myEditor.offsetToVisualPosition(endOffset)); Point point = new Point((startPoint.x + endPoint.x)/2, endPoint.y + myEditor.getLineHeight()); return new RelativePoint(myEditor.getContentComponent(), point); }