How do you add a key handler to a GWT FlexTable?

Posted by Eric Landry on Stack Overflow See other posts from Stack Overflow or by Eric Landry
Published on 2010-06-17T20:09:10Z Indexed on 2010/06/17 20:13 UTC
Read the original article Hit count: 423

Filed under:
|

I'm trying to change the row highlighting in my FlexTable using KeyCodes.KEY_UP/DOWN. This doesn't seem to work (based on 1809155):

public class KeyAwareFlexTable extends FlexTable 
      implements KeyDownHandler, HasKeyDownHandlers {
   public KeyAwareFlexTable() {
      this.addKeyDownHandler(this);
   }

   @Override
   public void onKeyDown(KeyDownEvent event) {
      GWT.log("onKeyDown");
      // check if up/down & do something useful
   }

   @Override
   public HandlerRegistration addKeyDownHandler(KeyDownHandler handler) {
      return addDomHandler(handler, KeyDownEvent.getType());
   }
}

I've also tried this (based on this site):

FlexTable table = new FlexTable() {
  @Override
  public void onBrowserEvent(Event event) {
     super.onBrowserEvent(event);
     GWT.log("Event type = " + DOM.eventGetType(event));
     switch (DOM.eventGetType(event)) {
     case Event.ONKEYDOWN:
        if (DOM.eventGetKeyCode(event) == KeyCodes.KEY_UP) {
           GWT.log("up");
        } else if (DOM.eventGetKeyCode(event) == KeyCodes.KEY_DOWN) {
           GWT.log("down");
        }
        break;
     default:
        break;
     }
   }
};
table.sinkEvents(Event.ONKEYDOWN);

I'm looking for a way to have this behavior more or less. Does anybody have a way to do this in GWT?

© Stack Overflow or respective owner

Related posts about events

Related posts about gwt