Hide balloon on mouse exit Follow
I have an inlay which I am adding to the end of some line in the editor.
I would like to display a balloon or tooltip when the user hovers over this inlay and hide the balloon when the mouse exits the ballon and inlay (i.e. mouse is not hovering either).
I added a mouse listener to the editor so when the mouse is over my inlay I display a balloon. How can I make this balloon disappear on mouse exit? I can probably implement this myself with the mouse listener, but surely there's a better way?
This is how I'm creating the balloon:
this.balloon = JBPopupFactory.getInstance()
Disposer.register(this.balloon, () -> this.balloon = null);
I tried using an IdeToolTip but that didn't work either (not sure I used the right components):
final JLabel label = new JLabel("Tooltip");
final JEditorPane pane = initPane("tooltip text",
final Wrapper wrapper = new Wrapper(pane);
this.ideTooltip = new IdeTooltip(editor.getComponent().getComponentAt(mouseEvent.getPoint()),
Please sign in to leave a comment.
Did you consider using HintManager instead? https://plugins.jetbrains.com/docs/intellij/notifications.html#editor-hints
I'm not sure. I'll take a look at it.
but the popup still closes only when I click outside it. I also tried:
with all sorts of hide flags but nothing gives the required behaviour. What am I missing?
Did you try com.intellij.codeInsight.hint.HintManager#HIDE_BY_MOUSEOVER
I have, and as the name suggests, the popup is closed whenever I move my cursor over it. I need the exact opposite behavior.
My popup contains links, so I want it to stay open when the cursor hovers over it and disappear when the cursor exits the popup.
It looks like LineTooltipRenderer uses a MouseMovementTracker with some logic to achieve this. Obviously I prefer not to copy this whole logic and use some built in API. This sounds like a pretty standard use case to me so I was hoping there's already something I can use?
To make things worse, our plugin currently supports version 2018 and I would prefer not to break this.
Unfortunately there's no ready-made API for your use-case. Indeed EditorMouseHoverPopupManager and MouseMovementTracker can be used as building/blocks inspirations in your plugin
Thanks very much for your help.
Would you guys consider adding such behavior (e.g. HintManager#HIDE_BY_MOUSEEXIT)? Should I submit a feature request somewhere?
Sure, you can file an RFE here https://youtrack.jetbrains.com/issues/IDEA