是否有可能在GWT中遍历网格地图?

时间:2014-04-10 12:51:30

标签: java gwt grid maps

问题

我已经检查了地图的内容,响应键甚至尝试手动抓取地图。出于某种原因,它只允许我创建一个地图,无论我选择哪一个。

我的尝试

OccupancyCheckView类

所以基本上我创建了一个对象,然后创建了这个Map:

private Map<String, Grid> resultGrids = new HashMap<String, Grid>(); //where String is the title of the grid

创建后,我只是允许用户抓住它:

public Map<String, Grid> getResultGrids() {
        return resultGrids;
    }

DataRun类

我在另一个类中进行RPC调用并等待响应:

public void onSuccess(Method method, Response response) 
            {   
                occupancyCheckView = new OccupancyCheckView(response.getResult()); //This simply passes a list of two strings which creates the titles and grids and puts them in a Map<String, Grid>

                Map<String, Grid> resultGrids = occupancyCheckView.getResultGrids(); //I've checked the contents by dumping the WidgetName.toString() to the screen and BOTH grids are there yet I can't seem to call both of them at the same time

        //so this is where I try accessing both grids

                for( String Name : response.getResult() ) { 
                    Label gridTitle = new Label(String.valueOf(resultGrids.containsKey(Name))); //both return back as true
                    gridTitle.setStyleName("gridTitle");
                    mainPanel_.add(gridTitle);
                    mainPanel_.add(resultGrids.get(Name)); //accesses the Map<String, Grid>
                    testMap.add(resultGrids.get(Name));
                    echo.setText("No Data");
                }

                //mainPanel_.add(resultGrids.get("FirstResponse")); 
                //mainPanel_.add(resultGrids.get("SecondResponse"));

            }

我没有编译错误。当我将各个部分打印到屏幕上时,一切都有效(问我是否要我检查任何东西)。在最后一部分,我注释了两个手动添加网格,如果我留下一个或两个,它仍然只显示一个网格,无论我选择哪一个。

修改

我如何创建网格:

private Grid occupancyGrid;

<Snip>

private void createResultGrid(List<String> gridName){

    occupancyGrid = new Grid(17,17);

    for (String Name_ : gridName){
    Label title = new Label();
    title.setText(Name_); 
    title.setStyleName("gridTitle"); //TODO style this

    for (int index=1;  index < occupancyGrid.getColumnCount(); index++){
        occupancyGrid.setWidget(0, index, new HTML("Cx"+Integer.toHexString(index-1)));
    }

    for (int index=1;  index < occupancyGrid.getRowCount(); index++){
        occupancyGrid.setWidget(index, 0, new HTML("Cx"+Integer.toHexString(index-1)));
    }

    resultLabels.put(Name_, title);
    resultGrids.put(Name_, occupancyGrid);
}
}

1 个答案:

答案 0 :(得分:1)

您可以添加两个网格,但第二个显示在第一个网格的顶部。例如,如果您的mainPanel_是LayoutPanel,则可能会发生这种情况。

尝试将两个网格添加到FlowPanel,然后将此FlowPanel添加到mainPanel_,或者,如果mainPanel_是LayoutPanel,则在添加时设置每个网格的位置。