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">

FocusPanel 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
                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
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment