【发布时间】: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