Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] SWT shell and events

Hi!
 
Thanks a real lot. It had been baffling me for quite a few days now. Yes it suffices like that.
 
Thanks for the patience :) Much appreciated! :)
Regards,
Krt_Malta


 
On Sun, Mar 14, 2010 at 1:03 PM, zhong nanhai <higerinbeijing@xxxxxxxxx> wrote:
I have tried many ways to implement such funtionality you want, but
there is not a very good way. I found that though you can get the bar
though text.getVerticalBar() but the bar does not belong to thie text
widget, so everytime the mouse move over on the bar, the mouseExit()
of the text has already been executed, then shell will be disposed()
with the code "shell.dispose()". Then you can not scroll the bar as
you want.

Though the bar is in the area of the window, but bar cann't handle any
mouse event; even though you add listener to this bar, nothing would
happen. So there is not a way to judge the mouse is move enter the bar
or exit the bar. Maybe we can do sth to let the bar know what happen:
when mouseExit of the text is executed, we can notify a mouseExit
event to the bar (and please make sure you have added the listener to
handle this kind of event), but unfortunately it can only be executed
once, after that the bar seems "die" and can not "hear" anything.

Because the shell is behind the text widget(included the bar), so
this's way the "mouse***" string cann't been printed in your first
snippet code. Then you can try sth to make the shell get focus or let
him can hear you and do what you tell him to do.

Any way, I think you should try another way to implement such
funtionality, though it is not such perfect. When you use Eclipse, you
should find that it's tooltip is wonderful and when you press 'F2'
button, a tooltip window will open, I think this kind of tooltip
'widget' may be much close to your requirements. Try the following
code:

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();
                       }

           });

When the tooltip window is open, if you click you mouse on any other
position outside of this window, the window will disapear(shell be
disposed).

On 3/13/10, Kurt Sultana <kurtanatlus@xxxxxxxxx> wrote:
> This link shows what I am trying to achieve.
>
> http://www.freeimagehosting.net/uploads/495027e997.jpg
>
>  It's a custom tooltip/preview option which shows some of the content of a
> website within Eclipse:
>
> When I move the mouse on the scrollbar, the shell gets disposed hence not
> allowing me to use the scrollbar. I want it to dispose when I move the mouse
> out of the text (including the scrollbar).
>
> How can I achieve this?
>
> Thanks and regards,
> Krt_Malta
>
> On Sat, Mar 13, 2010 at 10:05 AM, zhong nanhai
> <higerinbeijing@xxxxxxxxx>wrote:
>
>> Hi,
>>
>> The vertical scrollbar belongs to the Text box, so when you move the
>> mouse over it , MouseTrack event is produced, thus popup.dispose()
>> will be executed.
>>
>> In fact, I still does not understand well about what kind of
>> funtionality you want to implement and what kind of problems you want
>> to solve. If  you can explain more about the background of this
>> problem, we can give you more helpful information.
>>
>> Best wishes,
>>
>>
>>
>> On 3/13/10, Kurt Sultana <kurtanatlus@xxxxxxxxx> wrote:
>>  > Hi!
>> >
>> > I'm developing an Eclipse plug-in and I have a problem which is
>> reproduced
>> > in this small SWT application:
>> >
>> > public static void main(String[] args) {
>> >     Display display = new Display();
>> >     Shell shell = new Shell(display);
>> >     Text text = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.READ_ONLY |
>> > SWT.V_SCROLL);
>> >     text.setText("Hello");
>> >     shell.setLayout(new FillLayout());
>> >     shell.addMouseTrackListener(new MouseTrackListener() {
>> >
>> >       public void mouseEnter(MouseEvent arg0) {
>> >         System.out.println("mouseEnter");
>> >
>> >       }
>> >
>> >       public void mouseExit(MouseEvent arg0) {
>> >         System.out.println("mouseExit");
>> >
>> >       }
>> >
>> >       public void mouseHover(MouseEvent arg0) {
>> >         System.out.println("mouseHover");
>> >
>> >       }
>> >     });
>> >     // Display the window
>> >     shell.open();
>> >     while (!shell.isDisposed()) {
>> >       if (!display.readAndDispatch()) {
>> >         display.sleep();
>> >       }
>> >     }
>> >     display.dispose();
>> >   }
>> >
>> > 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 because if I attach it to the textbox, then
>> the
>> > shell would dispose when I touch the scrollbar.
>> >
>> > Thanks and regards,
>> > Krt_Malta
>> >
>>  _______________________________________________
>> platform-swt-dev mailing list
>> platform-swt-dev@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev
>>
>
_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top