1

我想在我的 LayoutPanel 中显示三个或更多 DataGrid,并将它们的宽度指定为 LayoutPanel 总宽度的百分比,但在 LayoutPanel 方法中,我只看到设置左右小部件宽度的方法。setWidgetLeftWidth()setWidgetRightWidth()

是否可以向 LayoutPanel 添加超过 2 个小部件,例如

layoutPanel.add(dataGrid1);
layoutPanel.add(dataGrid2);
layoutPanel.add(dataGrid3);
layoutPanel.add(dataGrid4);

然后将每个小部件的宽度设置为 LayoutPanel 宽度的 25%?

感谢和问候穆库尔

4

2 回答 2

2

您所拥有的将起作用,您需要做的就是使每个设置如下所示:

layoutPanel.add(dataGrid1);
layoutPanel.setWidgetLeftRight(dataGrid1, 0, Unit.PCT, 25, Unit.PCT);
于 2011-11-22T14:58:05.113 回答
1

好吧,我认为您也可以使用 LayoutPanel 来做到这一点,但是使用 DockLayoutPanel 要容易得多!这是您尝试使用 LayoutPanel 的示例的代码。

public void onModuleLoad() {

    //define a DockLayoutPanel with a Percentage size definition
    DockLayoutPanel dockLayoutPanel = new DockLayoutPanel(Unit.PCT);        

    //add four widgets to the DockLayoutPanel, each with a Percentage
    //with of 25%
    dockLayoutPanel.addWest(new Label("widget 1"), 25);
    dockLayoutPanel.addWest(new Label("widget 2"), 25);
    dockLayoutPanel.addWest(new Label("widget 3"), 25);

    //the last widget must always be added with the .add method 
    //since it takes the rest of the screen
    dockLayoutPanel.add(new Label("widget 4"));

    //set a with to the DockLayoutPanel (elso you don't se much)
    dockLayoutPanel.setWidth("500px");
    dockLayoutPanel.setHeight("500px");

    //add it to the RootPanel
    RootPanel.get().add(dockLayoutPanel);       
}

因此,只要您没有充分的理由必须使用 LayoutPanel,我就会使用 DocklayoutPanel!

于 2011-11-22T14:55:19.947 回答