# Displaying custom popups in RD mode that is sticky to the line

**URL:** <https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594>\
**Category:** IntelliJ Platform\
**Tags:** remote-development\
**Created:** [February 19, 2025, 1:04pm UTC](https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594 "2025-02-19T13:04:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mik.kondratek](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/mik.kondratek/32/113_2.png) [@mik.kondratek](https://platform.jetbrains.com/u/mik.kondratek)\
**Post date:** [February 19, 2025, 1:04pm UTC](https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594/1 "2025-02-19T13:04:14Z")

</div>

Hi there 👋

Straight to the point - I wanted to create a popup that will stick to the line and persistent when scrolling away. And I want to make it working in RD mode.

I struggled a lot and found out eventually, that in RD mode the component structure is different and I need some other way. I found this:  
[PopupFactory.html#getPopup-java.awt.Component-java.awt.Component-int-int-](https://docs.oracle.com/javase/8/docs/api/javax/swing/PopupFactory.html#getPopup-java.awt.Component-java.awt.Component-int-int-)

PopupFactory makes it possible to display a popup 🚀

Now I’d like to access editors visible rect to know the bounds.  
I tried `editor.contentComponent.visibleRect` but it returns width and height equal to 0.  
To be precise: It returns zeros in RD mode. Returns correct values in the regular run.

Here is my result in the regular mode (and my goal):  
 ![scroll-away-ezgif.com-video-to-gif-converter](https://us1.discourse-cdn.com/flex001/uploads/jetbrains_platform/original/1X/c0a479d130479b9cf53d4f88b984a775b74cb2f4.gif)

Can you help me? 🙏

Kind regards,  
Mikołaj Kondratek

---

<div class="post-metadata">

**Author:** ![kate.botsman](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/kate.botsman/32/356_2.png) [@kate.botsman](https://platform.jetbrains.com/u/kate.botsman)\
**Post date:** [February 21, 2025, 11:40am UTC](https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594/4 "2025-02-21T11:40:56Z")

</div>

Hi @mik.kondratek,

For editors, it’s generally better to use offsets rather than component coordinates.

If you’re looking for a popup that sticks to a specific position and remains visible while scrolling, `com.intellij.openapi.ui.popup.Balloon` is a good option—it properly handles positioning even in RD mode.

Here’s an example of how you can create a popup that sticks to the caret position:

```kotlin
val position = VisualPosition(line, column) // Use LogicalPosition if needed
JBPopupFactory.getInstance()
  .createBalloonBuilder(content)
  .createBalloon()
  .show(object : PositionTracker<Balloon>(editor.contentComponent) {
    override fun recalculateLocation(balloon: Balloon): RelativePoint {
      // Convert stored position to editor coordinates
      return RelativePoint(editor.contentComponent, editor.visualPositionToXY(position))
    }
  }, Balloon.Position.above)
```

---

<div class="post-metadata">

**Author:** ![mik.kondratek](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/mik.kondratek/32/113_2.png) [@mik.kondratek](https://platform.jetbrains.com/u/mik.kondratek)\
**Post date:** [March 13, 2025, 3:04pm UTC](https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594/6 "2025-03-13T15:04:13Z")

</div>

> [@kate.botsman](#):
>
> ```auto
> val position = VisualPosition(line, column) // Use LogicalPosition if needed
> JBPopupFactory.getInstance()
> .createBalloonBuilder(content)
> .createBalloon()
> .show(object : PositionTracker<Balloon>(editor.contentComponent) {
> override fun recalculateLocation(balloon: Balloon): RelativePoint {
> // Convert stored position to editor coordinates
> return RelativePoint(editor.contentComponent, editor.visualPositionToXY(position))
> }
> }, Balloon.Position.above)
> 
> ```

Thanks Kate.

It’s good that it is super convenient to use. However, I noticed an issue. The popup overlaps top parts of the IDE and some bottom parts too (tool windows). It also sticks to the border when reached during the scroll. Looks kind of buggy. See the example:  
 ![overlaps-demo](https://us1.discourse-cdn.com/flex001/uploads/jetbrains_platform/original/1X/f2bf3f680bf3d93ee960c7038fe15cc6fe376bb7.gif)

Is it possible to keep it in the editor’s layer? So it’s position does not change even if we scroll so far away that the popup is no longer visible.

---

<div class="post-metadata">

**Author:** ![kate.botsman](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/kate.botsman/32/356_2.png) [@kate.botsman](https://platform.jetbrains.com/u/kate.botsman)\
**Post date:** [March 24, 2025, 4:47pm UTC](https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594/7 "2025-03-24T16:47:20Z")

</div>

> [@mik.kondratek](#):
>
> Is it possible to keep it in the editor’s layer? So it’s position does not change even if we scroll so far away that the popup is no longer visible.

Unfortunately, we don’t support this behavior in our API to avoid inconsistencies in UI styling (borders, shadows, etc), missing popups (when it is scrolled out of view and forgotten) and to increase popups performance.

Of course, you can use default swing API, but in this scenario we can’t guarantee the compatibility with the Remote Dev setup.

Would it be possible for you to reconsider expected popup behavior here?

---

<div class="post-metadata">

**Author:** ![mik.kondratek](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/mik.kondratek/32/113_2.png) [@mik.kondratek](https://platform.jetbrains.com/u/mik.kondratek)\
**Post date:** [March 24, 2025, 5:02pm UTC](https://platform.jetbrains.com/t/displaying-custom-popups-in-rd-mode-that-is-sticky-to-the-line/594/8 "2025-03-24T17:02:22Z")

</div>

Got it! Thanks for the answer. Missing popups and performance are good reasons.

Yes, me and my team will reconsider our options. I think it the high level component you suggested is very convenient and easily maintainable solution. Scrolling issue does not seem to be a deal breaker.

Thanks again for your help and time!

Kind regards!
