在GWT中没有一种内置的方式可以做到这一点,把它放在那里也没有任何意义。你提到了一个网格,所以我猜你的数据大致接近某种形式的矩阵,在做很多假设的时候,你可能想要的粗糙技术是这样的:(这里没有编译器警告)
final Map<Button,Object> buttonToCellMap = new HashMap<Button,Object>();
ClickHandler myClickHandler = new ClickHandler() {
public void onClick(ClickEvent event){
Object thingInCell = buttonToCellMap.get((Button)event.getSource());
//do something with the thing in your grid here
}
}
for( List yourRow : matrix ){
for( Object yourObject : yourRow ){
//logic to make your grid cell goes here
Button aButton = new Button();
buttonToCellMap.put(aButton,yourObject);
aButton.addClickHandler(myClickHandler);
}
}
这将允许您在单击相应按钮后访问网格中位置x,y中所关心的对象。