我有一个包含两个(大的)组件的VerticalLayout :一个网格和一个图表。根据网格中的选择更新图表。为此,我使用了replaceComponent方法VerticalLayout。因此,当选择网格中的项时,图表会被更新,但是浏览器会滚动,而不是保持滚动位置。这可能是因为Vaadin首先从DOM中删除图表,然后添加新的图表。
更换组件时是否可以保持滚动位置?
到目前为止,我还没有在网上找到任何答案。必要的话我可以做一个SSCCE。
发布于 2016-04-03 12:26:28
由于André,我发现在被替换的组件上设置一个固定的高度可以解决这个问题。下面是一个SSCCE:
@Override
protected void init(VaadinRequest request) {
VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
layout.setSpacing(true);
setContent(layout);
TextField t1 = new TextField("Big field (1)");
t1.setWidth("300px");
t1.setHeight("1000px");
layout.addComponent(t1);
TextField t2 = new TextField("Big field (2)");
t2.setWidth("300px");
t2.setHeight("1000px");
layout.addComponent(t2);
final Component[] toReplace = new Component[] { t2 };
Button button = new Button("Click Me");
button.addClickListener(event -> {
Table t = new Table();
t.addContainerProperty("Name", String.class, null);
for (int i = 0; i < 20; i++) {
t.addItem(new Object[] { "" + i }, i);
}
//t.setHeight("200px");
layout.replaceComponent(toReplace[0], t);
toReplace[0] = t;
});
layout.addComponent(button);
setContent(layout);
}未设置高度时,会出现滚动问题。
https://stackoverflow.com/questions/36383720
复制相似问题