尽管文本框显示正常,但 vaadin 标签未显示

vaadin label not showing although the textbox appears fine

这是我写的class的构造函数,显示了文本框但没有显示标签:-

    public StartingTest(String op) {
    this.op = op;
    setStyleName("mainpanel");
    setCaption("Bonus Row");
    row = new GridLayout(2, 1);

    lblSource.setCaption("Source Profile: ");
    lblSource.setSizeUndefined();
    row.addComponent(lblSource, 0, 0);
    row.addComponent(txtSourceProfile, 1, 0);
    this.addComponent(row);
}

您的标签尺寸未定义。这意味着您的标签的宽度只是显示标签的 所必需的宽度。您的标签值为空,因此您看不到您的标签。解决方法是使用 setValue() 而不是 setCaption()。您也可以删除 setSizeUndefined() 并使用默认标签宽度 100%。