Friday, December 28, 2012

How to add MouseHandler in constructor? (NPE)

I know I can just bind any ui component to any events by using @UiHandler like this:

<g:FocusPanel ui:field="panel">

@UiField
FocusPanel panel;

@UiHandler("panel")
void handleClick(MouseDownEvent event) {
    //...
}

So far so good, but how can I "manually" add a mouse handler within the class constructor:
            panel.addMouseDownHandler(new MouseDownHandler() { //NPE
                @Override
                public void onMouseDown(MouseDownEvent event) {
                    Window.alert("mouse down");
                }
            });

If I write this in the constructor of the java class, I'm getting NullPointerException at this stage where the handler is added to the panel.
What am I missing here?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/IkAkkJ0IcP8J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment