2012-03-24 12 views
0

私はGUIのいくつかの要素をGWTフレームワークで作成しました。単純なonCLickメソッドを持つボタンが1つしかありません。ボタンがフォーカスを取得すると(setfocus(true))、トリガーはクリックイベントを自動的に発生させます。しかし、私はちょうどボタンが任意のイベントを発生させることなくフォーカスを保持したい。 簡単な方法でそれを作るには?Gwt:フォーカス後にクリックイベントを発生させない方法は?


私のコード:

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)** 
    } 

答えて

0

あなたが標準com.google.gwt.user.client.ui.Buttonを持っている場合は、それにsetFocus(true)を呼び出すと、そのボタンのClickHandlersをアクティブにしません。 Button.click()を明示的に呼び出すか、ユーザーが実際にボタンをクリックしていない限り、記述した内容は起こらないはずです。

関連する問題