0

当我执行下面的代码时,会显示图像,但名称不会显示在其下方。Window.alert 确实显示了正确的名称。所以错误必须在该行中:

flexTable.setWidget(row + 1, col, new Label(youthMember.getSurname() + ", " + youthMember.getFirstname()));

我在网上搜索过类似的代码,但找不到解决方案。

我正在使用 Eclipse Juno 和 GWT。

非常感谢您的帮助。

问候,

格林

 public void renderYouthMemberTable(List<YouthMember> youthMemberList) {
    if (youthMemberList != null) {
        int row = 0;
        int col = 0;
        flexTable.clear();
        for (final YouthMember youthMember : youthMemberList) {
            String imageDataString = youthMember.getPhotograph();

            //Display each image with the name under it.
            Image image = new Image(imageDataString);

            flexTable.setWidget(row, col, image);
            flexTable.setWidget(row + 1, col, new Label(youthMember.getSurname() + ", " + youthMember.getFirstname()));
            Window.alert("Name " + youthMember.getSurname() + ", " + youthMember.getFirstname());

            //Add click handler
            image.addClickHandler(new ClickHandler(){

                @Override
                public void onClick(ClickEvent event){
                    // Do something - Go to next view passing the ID
                    //returnID = youthMember.getId();
                    //Window.alert("returnID = " + returnID);
                    //navHandler.go(AwardOverview);
                    Window.alert("Picture clicked");
                }
            });

            //Go to next column and if the end of the columns
            //drop two rows and go to the first column
            col = col + 1;
            if (col > 7) {
                row = row + 2;
                col = 0;
            }
        }
    }

}

答案是显示名称。然而,它是不可见的。所以我将代码更改为(更改是在图像显示之后 - 始终有效):

flexTable.setWidget(row, col, image);
            Label lblYMname = new Label (youthMember.getSurname() + ", " + youthMember.getFirstname());
            lblYMname.setStyleName("gwt-Label-Login");
            lblYMname.setWidth("151px");
            flexTable.setWidget(row + 1, col, lblYMname);
4

1 回答 1

0

答案是显示名称。然而,它是不可见的。所以我将代码更改为(更改是在图像显示之后 - 始终有效):

flexTable.setWidget(row, col, image);
        Label lblYMname = new Label (youthMember.getSurname() + ", " + youthMember.getFirstname());
        lblYMname.setStyleName("gwt-Label-Login");
        lblYMname.setWidth("151px");
        flexTable.setWidget(row + 1, col, lblYMname);
于 2014-05-08T06:40:52.940 回答