GWT:从ClickHandler中的函数返回VerticalPanel

时间:2014-07-19 11:58:28

标签: gwt return popuppanel

我想在点击图片时弹出一个窗口。下面是一段代码:

while(index<bookList.size()){
        if(cellCount<4){
            image[index] = new Image(imageList.get(index));
            final int imageIndex = index;
            table.setWidget(row, cellCount, new Image(bookList.get(index)));
            table.addClickHandler(new ClickHandler(){

                @Override
                public void onClick(ClickEvent event) {
                    VerticalPanel vPanel = new VerticalPanel();
                    vPanel = imageDetail.getPopup(popup, image[imageIndex]);
                    popup.setAnimationEnabled(true);
                    popup.setGlassEnabled(true);
                    popup.setAutoHideEnabled(false);
                    popup.setWidth("300px");
                    popup.setHeight("300px");
                    popup.add(vPanel);
                    popup.center();
                }});
            table.getFlexCellFormatter().setStyleName(row, cellCount, "ImageCell");
            cellCount++;
            index++;
        }

上面的代码包含clickhandler,它调用imageDetail对象的“getPopup”。 “getPopup”函数返回一个垂直面板,该面板被添加到PopupPanel。 ImageDetail类如下

public class ImageDetails extends Composite {
private Image closeButton;

VerticalPanel getPopup(final PopupPanel popup, Image image){
    VerticalPanel vPanel = new VerticalPanel();

    //Close Button
    HorizontalPanel closePanel = new HorizontalPanel();
    closeButton = new Image("/Images/closebutton.jpg");
    closeButton.addClickHandler(new ClickHandler(){

        @Override
        public void onClick(ClickEvent event) {
            // TODO Auto-generated method stub
            popup.hide();

        }});
    closePanel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
    closePanel.add(closeButton);
    vPanel.add(closePanel);

    VerticalPanel imagePanel = new VerticalPanel();
    imagePanel.add(image);
    vPanel.add(imagePanel);

    return vPanel;

}

我的问题如下: 1)从功能返回面板是否可以?如果不是,为什么呢?如果是,为什么上面的代码给出了“未捕获的异常转义com.google.gwt.event.shared.UmbrellaException:捕获了3个异常:null; null; null”?

2)当我尝试在“getPopup”函数中添加垂直面板到弹出面板并从那里获取弹出面板时,代码返回与第一个问题中提到的相同的错误。我错过了什么?

我是否缺少任何initWidget(w)函数调用?

谢谢

0 个答案:

没有答案