我正在尝试使用KeyCodes.KEY_UP / DOWN更改FlexTable中的行突出显示。这似乎不起作用(基于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());
}
}
我也试过这个(基于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);
我正在寻找一种方法让this behavior或多或少。有没有人有办法在GWT中做到这一点?
答案 0 :(得分:3)
搞定了
FocusPanel focus = new FocusPanel(flexTable);
focus.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
int code = event.getNativeKeyCode();
if (KeyCodes.KEY_UP == code) {
GWT.log("Bed goes up");
} else if (KeyCodes.KEY_DOWN == code) {
GWT.log("Bed goes down");
}
}
});