gpt4 book ai didi

java - Vaadin - 布局调整大小重叠

转载 作者:行者123 更新时间:2023-11-30 10:25:36 26 4
gpt4 key购买 nike

我在尝试调整浏览器大小时面临与我的项目重叠的问题。我尝试了很多不同的变体来让它工作,但结果仍然是 Not Acceptable 。

调整大小之前: enter image description here

ABC 包含在VerticalLayout 中- 我将其称为 root

现在,当我尝试调整浏览器大小时(如箭头所示)C 开始窃取其他组件的位置。

调整大小后: enter image description here

我想要达到的效果是我的网格 (C) 没有试图适应我的浏览器。它不应该移动,只是隐藏 - 如下所示(绿色显示实际可见的部分):

effect I would like to achieve

    /*ROOT class that extends VerticalLayout*/
private void init()
{
super.setSizeFull();

addA();
addB();
addC();
}

private void addA()
{
Label header = new Label();

super.addComponent(header);
super.setComponentAlignment(header, Alignment.MIDDLE_CENTER);
}

private void addB()
{
layoutB.setSizeFull();
layoutB.setWidth("92%");
super.addComponentsAndExpand(layoutB);
super.setExpandRatio(layoutB, 0.3f);
super.setComponentAlignment(layoutB, Alignment.MIDDLE_CENTER);
}

private void addC()
{
grid.setSizeFull();
grid.setColumnReorderingAllowed(true);

grid.setWidth("92%");
super.addComponentsAndExpand(grid);
super.setExpandRatio(grid, 0.6f);
super.setComponentAlignment(grid, Alignment.BOTTOM_CENTER);
}

如您所见,C 的添加方式与 B 相同,但只有 C 在移动。在此先感谢您的帮助!

我正在使用 Vaadin 8。

@编辑:

@SpringUI(path = "/ui")
public class MyUI extends UI {

@Override
protected void init(VaadinRequest request)
{
Workspace workspace = new Workspace();

HorizontalLayout root = new HorizontalLayout();
root.setSizeFull();
root.addComponentsAndExpand(workspace);

setContent(root);
}

public class Workspace extends Panel
{
public Workspace()
{
init();
}

private void init()
{
setSizeFull();
addStyleName(ValoTheme.PANEL_BORDERLESS);

VerticalLayout layout = new VerticalLayout();
// by default width 100% and height undefined in Vaadin 8
setContent(layout);

// component A
Label label = new Label("Test1");
layout.addComponent(label);

// component B
HorizontalLayout bar = new HorizontalLayout();
bar.addComponents(new Label("Label 1"), new Label("Label 2"));
layout.addComponent(bar);

// component C
Grid<MyBean> grid = new Grid<>(MyBean.class);
grid.setCaption("My Grid:");
grid.setHeight("1000px");
//grid.setHeightByRows(50); // same as fixed height
List<MyBean> items = new LinkedList<>();
IntStream.range(1, 100).forEach(i -> items.add(new MyBean("Item " + i)));
grid.setItems(items);
layout.addComponent(grid);
}
}

public static class MyBean {
private String name;
public MyBean(String name) { this.name = name; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}

}

最佳答案

看看这个工作示例:

@SpringUI(path = "/ui")
public class MyUI extends UI {

@Override
protected void init(VaadinRequest request) {
Panel panel = new Panel();
panel.addStyleName(ValoTheme.PANEL_BORDERLESS);
panel.setSizeFull();

VerticalLayout layout = new VerticalLayout();
// by default width 100% and height undefined in Vaadin 8
panel.setContent(layout);

// component A
Label label = new Label("Test1");
layout.addComponent(label);

// component B
HorizontalLayout bar = new HorizontalLayout();
bar.addComponents(new Label("Label 1"), new Label("Label 2"));
layout.addComponent(bar);

// component C
Grid<MyBean> grid = new Grid<>(MyBean.class);
grid.setCaption("My Grid:");
grid.setHeight("1000px");
//grid.setHeightByRows(50); // same as fixed height
List<MyBean> items = new LinkedList<>();
IntStream.range(1, 100).forEach(i -> items.add(new MyBean("Item " + i)));
grid.setItems(items);
layout.addComponent(grid);

setContent(panel);
}

public static class MyBean {
private String name;
public MyBean(String name) { this.name = name; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}

}

Grid 具有固定的高度(按像素或行数)。 VerticalLayout 不需要扩展比率。 Panel 中的布局将根据其子组件的需要进行扩展。如果高度大于 Panel 的可用空间,则会显示滚动条。

关于java - Vaadin - 布局调整大小重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46097254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com