我想在LayoutPanel中显示三个或更多DataGrids,并将它们的宽度指定为LayoutPanel总宽度的百分比,但在LayoutPanel方法中,我只看到设置左右窗口小部件宽度的方法。 setWidgetLeftWidth()
和setWidgetRightWidth()
。
是否可以向LayoutPanel添加2个以上的小部件,如
layoutPanel.add(dataGrid1);
layoutPanel.add(dataGrid2);
layoutPanel.add(dataGrid3);
layoutPanel.add(dataGrid4);
然后将每个窗口小部件的宽度设置为LayoutPanel宽度的25%?
谢谢和问候 穆库尔
答案 0 :(得分:2)
您所拥有的功能,您需要做的就是使每个设置如下:
layoutPanel.add(dataGrid1);
layoutPanel.setWidgetLeftRight(dataGrid1, 0, Unit.PCT, 25, Unit.PCT);
答案 1 :(得分: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!