ravi
ravi

Reputation: 1847

Capturing mouse events on horizontal panel in GWT

Is there a way to capture mouse events on a horizontal panel in gwt ? I am trying to capture mousedown or onclick events but m not able to get it working. This is what i have done so far

final HorizontalPanel container = new HorizontalPanel() {
        @Override
        public void sinkEvents(int eventBitsToAdd) {
            // TODO Auto-generated method stub
            super.sinkEvents(Event.ONCLICK);
        }

        @Override
        public void onBrowserEvent(final Event event) {
            // TODO Auto-generated method stub
            super.onBrowserEvent(event);
            if (DOM.eventGetType(event) == Event.ONCLICK) {
                    System.out.println("event type -->> " + event.getType());
            }
            /*if(Event.ONMOUSEDOWN == arg0.getTypeInt())
            System.out.println("event type -->> " + arg0.getType());*/
        }

    };

I have no clue why this doesn't work. any help would be appreciated. Thanks

Upvotes: 2

Views: 3640

Answers (2)

Vitalii Dudok
Vitalii Dudok

Reputation: 11

You can use FocusPanel. For example:

HorizontalPanel yourContainer = new HorizontalPanel();

FocusPanel wrapper = new FocusPanel();
wrapper.add(yourContainer );

wrapper.addClickHandler(new ClickHandler() {
  @Override
  public void onClick(ClickEvent event) {
    // Handle the click
  }
});

Upvotes: 0

Danny Kirchmeier
Danny Kirchmeier

Reputation: 1134

Instead of manually sinking and reading events, you could consider using Widget#addDomHandler():

HorizontalPanel container = new HorizontalPanel();
ClickHandler cHandler = new ClickHandler(){ /* ... */ };
MouseDownHandler mdHandler = new MouseDownHandler(){ /* ... */ };
container.addDomHandler(cHandler, ClickEvent.getType());
container.addDomHandler(mdHandler, MouseDownEvent.getType());

Upvotes: 7

Related Questions