java - 在 Vaadin 中使用嵌套的 Horizo​​ntalSplitPanel 和 VerticalSplitPanel 创建布局

标签 java jakarta-ee vaadin vaadin7 splitter

我是 vaadin 的新手,正在尝试设置基本布局。这是我的代码:

    //a label
    public static final String brownFox = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. ";

@Override
protected void init(VaadinRequest request) {

    VerticalLayout layout = new VerticalLayout();
    setContent(layout);

    // First Main horizontal split panel
    final HorizontalSplitPanel horizontal1 = new HorizontalSplitPanel();
    horizontal1.setHeight("100%");
    horizontal1.setSplitPosition(20, Sizeable.UNITS_PERCENTAGE);
    layout.addComponent(horizontal1);

    // add a label to the left area
    horizontal1.setFirstComponent(new Label(brownFox));

    // Second main horizontal split panel
    final HorizontalSplitPanel horizontal2 = new HorizontalSplitPanel();
    horizontal2.setHeight("100%");
    horizontal1.setSecondComponent(horizontal2);
    horizontal2.setSplitPosition(80, Sizeable.UNITS_PERCENTAGE);

    // First main vertical split panel
    final VerticalSplitPanel vertical1 = new VerticalSplitPanel();
    vertical1.setWidth("100%");
    horizontal2.setFirstComponent(vertical1);

    vertical1.setFirstComponent(new Label(brownFox));
    vertical1.setSecondComponent(new Label(brownFox));
    vertical1.setSplitPosition(50, Sizeable.UNITS_PERCENTAGE);
    horizontal2.setSecondComponent(new Label(brownFox));}

渲染的布局是:

enter image description here

问题出在VerticalSplitPanel第二个组件和分割器上。标签被隐藏,并且分离器不在屏幕中间。

感谢您的帮助。

最佳答案

VerticalLayout 默认情况下是自动/未定义高度,因此将其设置为 100% 以占用 UI 中的所有可用空间。

@Override
protected void init(VaadinRequest request) {

  VerticalLayout layout = new VerticalLayout();
  setContent(layout);
  // Add this
  layout.setHeight("100%");

  // The rest is the same
  ...

关于java - 在 Vaadin 中使用嵌套的 Horizo​​ntalSplitPanel 和 VerticalSplitPanel 创建布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25831221/

相关文章:

java - 访问 Java Web 项目中的动态资源

java - 更改 PopupWindow 中 TextView 的文本不起作用

java - Java 奇怪的 Eclipse 编译错误

jakarta-ee - 焊接-001408 : Unsatisfied dependencies in OpenLiberty with implicit bean scanning (CDI) disabled

java - Vaadin 中类似 anchor 的功能,可以跳转/滚动到某个点

java - 将 spring boot 与 vaadin 结合使用时,js 文件出现 404

java - ListView 未反射(reflect) notifyDataSetChanged() 的更改

java - 使用 Servlet 和准备好的语句更新类未找到异常(MySQL 驱动程序)

themes - 通过代码更改 Vaadin 7 中的主题

java - Activity崩溃生命周期方法——android