tags:

views:

98

answers:

1

Hi!

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) { 
          popup.dispose();   
       }    
       public void mouseEnter(MouseEvent e) { 
       } 
    });
popup.setSize(200, 100);
text.setText("The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog");
popup.open();

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

A: 

Hi!

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

text.forceFocus();
           text.addFocusListener(new FocusListener(){

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

                       @Override
                       public void focusLost(FocusEvent arg0) {
                               // TODO Auto-generated method stub
                               shell.dispose();
                       }

           });

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

Krt_Malta