views:

156

answers:

2

Hi!

I'm implementing a custom preview/tooltip for an Eclipse plug-in. It did it using a Shell in SWT, removing all its trimmings and placing a text box inside it. It looks great. However now I need to dispose of the shell when the cursor moves out of the shell window and I ran into some issues:

Does it make sense to attach a mousemoveListener to the shell? First I was doing this but then I realized that this listener only captures mouse move Events which occur inside the shell. How will I capture the mouse going out of the shell so as I could dispose of it?

Thanks and regards, Krt_Malta

+2  A: 

Attach a MouseTrackListener with MouseTrackAdapter as a listener and override mouseExit() method.

pajton
Thanks that was brilliant, it did the trick! Now one technicality: strictly speaking i'm attaching the listener to the textbox inside the shell and not the shell since I'm not getting events generated for the shell for some reason I'm not aware of. Hence when I move to the scrollbar on the right of the textbox, the shell is being disposed since the mouse has moved out of the textbox. How can I attach the listener to the shell please?Thanks and regards,Krt_Malta
Krt_Malta
You can attach it to the shell directly, shell is a widget as well.
pajton
A: 

It allows me to attach it fine ok. But no events are generated so it's not disposed. This is how I am doing it:

final Shell popup = new Shell(PlatformUI.getWorkbench().getDisplay(), SWT.TOOL); 

    popup.addMouseTrackListener(new MouseTrackListener() { 
    public void mouseHover(MouseEvent e) { 
    } 
    public void mouseExit(MouseEvent e) { 
         popup.dispose(); 
    }
    public void mouseEnter(MouseEvent e) { 
    } 
    }); 

Why isn't it working? Thanks and regards, Krt_Malta

Krt_Malta
Please note that this is a Q/A site, not a forum. If you need to provide additional info, edit your original question rather than add it as an answer.
Helen