How to show a hover popup with SWT StyledText

643 Views Asked by At

I am using SWT's StyledText and I am wondering how I would detect if the user hovers over a word for more then 3 seconds. An example of what I mean is how Eclipse has a popup that shows, when you hover over a text.

3

There are 3 best solutions below

0
greg-449 On BEST ANSWER

You can use a 'mouse track listener' to listen for mouse hover events. However you can't set the hover time for this:

control.addMouseTrackListener(MouseTrackListener)

MouseTrackListener has three events - mouseEnter, mouseExit and mouseHover.

0
SomeDude On

I believe those are tooltips that appear when you hover over a text for e.g. in Java editor. See here for tooltip doc and here for examples on how real production code uses eclipse tooltips.

0
Rüdiger Herrmann On

While you can implementet text hover yourself, with a MouseTrackListener like suggested by Greg, you can also use the JFace TextViewer.

The TextViewer provides a higher-level abstraction for text hover. With its setTextHover() methods you can set a callback, that is informed when a text hover for a certain region should be shown.

This is also the method that is used by Eclipse text editors.