当我点击GWT / MGWT中的面板时要执行的事件 [英] An event to be performed when I click a Panel in GWT/MGWT

查看:339
本文介绍了当我点击GWT / MGWT中的面板时要执行的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在点击面板时执行一个事件,就像用户点击一个按钮时发生的一样。



我需要这个命令以处理这个面板上的点击事件。

web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/FocusPanel.htmlrel =nofollow> FocusPanel ,这使得它的内容变得可以聚焦,并增加了捕捉鼠标和键盘事件的能力。因此,在 FocusPanel 中包装面板

  Panel panel = new Panel(); //你的面板(ex; hPanel,vPanel)
FocusPanel focusPanel = new FocusPanel();

focusPanel.addClickListener(new ClickListener(){

public void onClick(Widget sender){
// TODO自动生成的方法存根
}

});

focusPanel.add(面板);

还有一种可能性(没有FocusPanel)

  Horizo​​ntalPanel hpanel = new Horizo​​ntalPanel(); 
hpanel.sinkEvents(Event.CLICK);
hpanel.addHandler(new ClickHandler(){
$ b @Override
public void onClick(ClickEvent event){
// TODO自动生成的方法存根

}
},ClickEvent.getType());


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.

解决方案

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());

这篇关于当我点击GWT / MGWT中的面板时要执行的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆