Mop*_*ath 1 onkeypress smartgwt
我正在smartGWT项目中的tile网格上加载文件图标.按Enter键时,我想打开所选文件进行显示.
当我覆盖onKeyPress处理程序时,它确实有效,但使用左/右/上/下箭头键的tile网格导航行为将丢失.
我的问题是..,如何保留默认处理行为,同时仍然覆盖Enter键.
tileGrid.addKeyPressHandler (new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
if (EventHandler.getKey().equals("Enter")) {
//do something special here
}
else {
**//TODO: do the default processing..**.
}
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:
@Ras,这是模拟问题的代码.
package com.rv.gwtsample.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.widgets.events.KeyPressEvent;
import com.smartgwt.client.widgets.events.KeyPressHandler;
import com.smartgwt.client.widgets.tile.TileGrid;
import com.smartgwt.client.widgets.tile.TileRecord;
/**
* @author rvnath
*
*/
public class MyTileGrid implements EntryPoint {
/* (non-Javadoc)
* @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
*/
@Override
public void onModuleLoad() {
// TODO Auto-generated method stub
TileGrid grid = new TileGrid();
grid.setLeft(50);
grid.setTop(50);
grid.setWidth("300");
grid.setHeight("200");
DetailViewerField field = new DetailViewerField("Name");
grid.setFields(field);
grid.addKeyPressHandler(new KeyPressHandler() {
@Override
public void onKeyPress(KeyPressEvent event) {
if (event.getKeyName().equals("Enter"))
GWT.log("Enter pressed");
}
});
Record[] rec = new TileRecord[32];
for (int i=0; i<32; ++i) {
rec[i] = new TileRecord();
}
grid.setData(rec);
grid.draw();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我禁用onKeyPress处理程序,箭头键可以在tile网格的元素之间导航.如果我启用,则整个切片网格面板会滚动,而不是选择更改.
而不是使用KeyPressHandler,尝试KeyDownHandler,它的工作原理.
tileGrid.addKeyDownHandler(new KeyDownHandler() {
@Override
public void onKeyDown(KeyDownEvent event) {
if (EventHandler.getKey().equalsIgnoreCase("Enter")){
openModal(tileGrid.getSelectedRecord());
}
}
});
Run Code Online (Sandbox Code Playgroud)
测试了最新的3.0 smartgwt版本.
归档时间: |
|
查看次数: |
3402 次 |
最近记录: |