图像数组上的onMouseOver事件仅在gwt中被调用一次

时间:2014-07-15 08:18:49

标签: eclipse gwt

我有一个附加到DeckPanel的图像阵列。我想要的是鼠标悬停在mouseOut上消失的图像上的弹出窗口。

代码如下:

final PopupPanel popup = new PopupPanel();
        for(int i=0; i<images.size();++i){
            final int index = i;
            image[i] = new Image(images.get(i));
            image[i].addMouseOutHandler(new MouseOutHandler(){

                @Override
                public void onMouseOut(MouseOutEvent event) {
                    // TODO Auto-generated method stub
                    popup.hide();
                }});
            image[i].addMouseOverHandler(new MouseOverHandler(){

                @Override
                public void onMouseOver(MouseOverEvent event) {
                    // TODO Auto-generated method stub
                    Label label = new Label(images.get(index));
                    popup.add(label);
                    popup.showRelativeTo(image[index]);
                }});
            image[i].addClickHandler(new ClickHandler(){

                @Override
                public void onClick(ClickEvent event) {
                    // TODO Auto-generated method stub
                    Window.alert("image clicked");
                }});
            deck.add(image[i]);
        }

问题:onMouseOver()只获得一次。你能不能帮我理解这里发生的事情以及如何在每次加载数据图像时告诉我如何使它适用于所有图像?

1 个答案:

答案 0 :(得分:0)

onMouseOver你反复向popup添加标签.PopupPanel是一个SimplePanel它只能添加一个widget.So onMouserOver首先清除PopupPanel

popup.clear();
Label label = new Label(images.get(index));
popup.add(label);
popup.showRelativeTo(image[index]);