Take the 2-minute tour ×

I'm developing an Eclipse plug-in and I have a problem which is reproduced here:

    popup = new Shell(PlatformUI.getWorkbench().getDisplay(), SWT.TOOL );
    popup.setLayout(new FillLayout());
    Text text = new Text(popup, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
    text.setBackground(new org.eclipse.swt.graphics.Color(PlatformUI.getWorkbench().getDisplay(), 255, 255, 204));
    text.addMouseTrackListener(new MouseTrackListener() { 
       public void mouseHover(MouseEvent e) { 
       public void mouseExit(MouseEvent e) { 
       public void mouseEnter(MouseEvent e) { 
popup.setSize(200, 100);

As you can see I'm creating a shell and putting a Textbox inside it and putting it all across the shell. Then I attach a MouseTrackListener to the shell. The events don't fire (as in when I hover in the shell "mouseHover" is not printed etc). When I remove the Textbox the events fire. Can anyone tell me where the problem lies please? I don't want to attach a listener to the textbox but to the shell. I'll really appreciate the help because I've been trying to trace it for quite some time now.

Thanks and regards, Krt_Malta

share|improve this question
Any ideas please? I'm open to alternative implementations... –  Krt_Malta Mar 12 '10 at 15:10
Please see this answer (which could also help here): stackoverflow.com/a/10825659/305973 –  robinst May 30 '12 at 23:34
add comment

2 Answers

up vote 1 down vote accepted

A kind person from the Eclipse SWT mailing list gave me this solution:

           text.addFocusListener(new FocusListener(){

                       public void focusGained(FocusEvent arg0) {
                               // TODO Auto-generated method stub

                       public void focusLost(FocusEvent arg0) {
                               // TODO Auto-generated method stub


It's not exactly 100% what I wanted (since it seems that what I want can't be easily achieved) but it's great still. Hope it helps anyone who encounters the same problem.

Regards, Krt_Malta

share|improve this answer
add comment

I have a 'better' solution - depending on your preference.

Set the text to be 1 or 2 pixels smaller all round than the shell it is in. The shell thus offers a border effect around the text.

Set the mouseExit on the shell.

This will give the correct behaviour - with one terrible problem. As the mouse enters the text+shell combo, a mouseExit is generated by the mouse leaving the shell into the text box.

I have set a flag (boolean mouseIn_flag) which is first false. On a mouseExit it is set true. If it is true on mouseExit - shell.close() ;

The effect is that it ignores the first mouseExit, and allows the mouse into the text. It performs a shell close when the mouse exits the text (and thus enters the shell) and then exits the shell.

Since the shell is only a one/two pixel border around the text, the user would have to work hard at strange movements to incorrectly trigger these events.

share|improve this answer
add comment

Your Answer


