An event to be performed when I click a Panel in GWT/MGWT [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 16:26:30

问题


I want to perform an event when I click on a panel, in the same way this happens when the user clicks on a button.

I need this in order to handle events on click for this panel.


回答1:


You have to use GWT FocusPanel which makes its contents focusable, and adds the ability to catch mouse and keyboard events. So wrap your panel inside FocusPanel.

Panel panel = new Panel();    //Your panel here(ex;hPanel,vPanel)
FocusPanel focusPanel = new FocusPanel();

focusPanel.addClickListener(new ClickListener(){

    public void onClick(Widget sender) {
        // TODO Auto-generated method stub
    }

});

focusPanel.add(panel); 

One more possibility(without FocusPanel)

 HorizontalPanel hpanel = new HorizontalPanel();
        hpanel.sinkEvents(Event.CLICK);
        hpanel.addHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                // TODO Auto-generated method stub

            }
        }, ClickEvent.getType());



回答2:


I would make a new widget ( extending in this example an Absolute panel ) that implements the HasClickHandlers interface like this

public class MyCustomPanel extends AbsolutePanel
implements HasClickHandlers
{
    public HandlerRegistration addClickHandler(
        ClickHandler handler)
    {
        return addDomHandler(handler, ClickEvent.getType());
    }
}

And then in my code I would do it like this

MyCustomPanel mPanel = new MyCustomPanel();
mPanel.addClickHandler(new ClickHandler() {
    public void onClick(ClickEvent event) {
        // Do on click stuff here.
    }
});


来源:https://stackoverflow.com/questions/15547070/an-event-to-be-performed-when-i-click-a-panel-in-gwt-mgwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!