【问题标题】:Gwt : How to not to fire a click event after focus?Gwt:如何在焦点后不触发点击事件?
【发布时间】:2012-03-24 20:24:45
【问题描述】:

我已经使用 GWT 框架创建了我的 GUI 的一些元素。我只有一个带有简单 onCLick 方法的按钮。当按钮获得焦点 (setfocus(true)) 时,触发器会自动触发点击事件。但我只想让按钮保持焦点而不触发任何事件。 如何以简单的方式制作它?


我的代码:

public void onModuleLoad(){
..............
    textBoxTx = new TextBox();
    textBoxTx.addKeyDownHandler(new KeyDownHandler() {
    public void onKeyDown(KeyDownEvent event) {
        switch(event.getNativeKeyCode()){ 
        case KeyCodes.KEY_ENTER: addTx();
    }
        }
   });
....
protected void addTx() 
    final String tx = textBoxTx.getText().toUpperCase().trim();
    textBoxTx.setFocus(true);
    if (!tx.matches("^[0-9\\.]{1,10}$")) {
        Window.alert("'" + tx + "' n'est pas valide .");
        textBoxTx.selectAll();
        return;
      }
    textBoxTx.setText("");
    param_Tx=Double.parseDouble(tx);
    if (param_An==0)
        rateFlexTable.setText(1, 2, tx);
    else
    {
    for (int i=1;i<=param_An;i++)
    rateFlexTable.setText(i, 2,tx);
    rateFlexTable.setText(param_An, 4,"");
    }
**// fire the click event of my button when I give the focus**
    **btnCalcul.setFocus(true)**
    }

【问题讨论】:

    标签: events gwt button onclick focus


    【解决方案1】:

    如果你有一个标准的com.google.gwt.user.client.ui.Button,在它上面调用setFocus(true) 不会激活那个按钮的ClickHandlers。如果您可以共享一些代码可能会很好,因为除非您明确调用 Button.click() 或用户实际点击按钮,否则您所描述的不应发生。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多