Friday, December 28, 2012

How to the same MouseHandler to multiple components?

I have several same components that at this stage just perform the same operation.

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

FocusPanel panel, panel2, panel3;

void handleClick(MouseDownEvent event) {
void handleClick2(MouseDownEvent event) {
void handleClick3(MouseDownEvent event) {

So far so good, but how can I "manually" add a mouse handler inside a loop like within the class constructor:
    for (FocusPanel panel : panels) {
            panel.addMouseDownHandler(new MouseDownHandler() {
                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.

Is there any way that I can add these kind of mouseHandlers in the constructor? Or can elements bound via @UiField only be handlers attached via @UiHandler??

Alternativly, do you know of any workaround of adding the same MouseHandler to a bunch of objects as I'm trying in this example?

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