在FlexTable中显示标签的问题

时间:2013-05-20 06:08:04

标签: java eclipse gwt

当我执行下面的代码时,会显示图像,但名称不会显示在其下方。 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);

1 个答案:

答案 0 :(得分: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);