gxt (ext gwt) 网格和列宽
我正在尝试创建一个填充 ContentPanel
宽度的网格。网格应该有两列大小相等且横跨网格的整个宽度。调整浏览器窗口大小应相应更新网格大小。我希望下面的代码能够完成此任务,但是网格不会随着浏览器大小的调整而增长,并且第二列和网格右边缘之间存在 ~15px
间隙。
有什么想法吗?
public class MyGrid extends ContentPanel {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FillLayout());
ColumnConfig c1 = new ColumnConfig("value","value", 50);
ColumnConfig c2 = new ColumnConfig("value1","value1", 50);
ListStore<ModelData> store = new ListStore<ModelData>();
for (int i=0; i<10; i++) {
BaseModelData data = new BaseModelData();
data.set("value", "value");
data.set("value1", "value1");
store.add(data);
}
Grid<ModelData> grid = new Grid<ModelData>(store, new ColumnModel(Arrays.asList(new ColumnConfig[] {c1, c2})));
grid.setAutoHeight(true);
grid.setAutoWidth(true);
grid.getView().setAutoFill(true);
add(grid);
}
}
I am trying to create a grid that fills the width of a ContentPanel
. The grid should have two columns of equal size that span the entire width of the grid. Resizing the browser window should update the grid size accordingly. I would expect the code below to accomplish this, but the grid does not grow on browser resize and there is a ~15px
gap between the second column and the right edge of the grid.
Any ideas?
public class MyGrid extends ContentPanel {
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
setLayout(new FillLayout());
ColumnConfig c1 = new ColumnConfig("value","value", 50);
ColumnConfig c2 = new ColumnConfig("value1","value1", 50);
ListStore<ModelData> store = new ListStore<ModelData>();
for (int i=0; i<10; i++) {
BaseModelData data = new BaseModelData();
data.set("value", "value");
data.set("value1", "value1");
store.add(data);
}
Grid<ModelData> grid = new Grid<ModelData>(store, new ColumnModel(Arrays.asList(new ColumnConfig[] {c1, c2})));
grid.setAutoHeight(true);
grid.setAutoWidth(true);
grid.getView().setAutoFill(true);
add(grid);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
表格右侧多余空间的原因是
grid.setAutoHeight()
。删除它,它就会消失。使用浏览器调整表格大小似乎需要使用Viewport
(我不明白为什么ContentPanel
会在上面代码中没有网格的情况下增长)。这段代码完成了我想要做的事情:The cause of the extra space on the right of the table is
grid.setAutoHeight()
. Remove this and it will be gone. Getting the table to resize with the browser seems to require the use of aViewport
(I dont understand why theContentPanel
would grow without the grid in the code above). This code accomplishes what I was trying to do:你试过这个吗?
网格将适合其容器。另外,您确实应该使用其他容器布局以使内部元素适合容器(FitLayout、BorderLayout、RowLayout 都可以接受)
Have you tried this?
Grid will fit its container. Also you really should use other layout for container to make inner elements fit container (FitLayout, BorderLayout, RowLayout are acceptable)