GWT切换按钮

时间:2011-01-20 14:04:18

标签: gwt togglebutton

我想添加一个处理程序,当gwt切换按钮显示下方时,该处理程序继续执行。我正在尝试keydown,但这不起作用。切换按钮中是否有任何方法允许这个?

1 个答案:

答案 0 :(得分:0)

使用Timer

ToggleButton myToggle = new ToggleButton();

Timer myTimer = new Timer() {
  @Override
  public void run() {
    if (myToggle.isDown()) {
      // Perform repeating action.
    } else {
      cancel();
    }
  }
};

myToggle.addValueChangeHandler(new ValueChangeHandler<Boolean>() {
  @Override
  public void onValueChange(ValueChangeEvent<Boolean> event) {
    if (event.getValue().booleanValue() == true) {
      // Perform the repeating action twice/second.
      myTimer.scheduleRepeating(500);
    }
  }
});