Vaadin 文本字段在框的左侧而不是在顶部带有标题?

Vaadin Textfields with caption at the left of the box instead of on top?

如何让我的文本字段标题位于文本框的左侧而不是默认位于其顶部?

HorizontalLayout hLayout = new HorizontalLayout();
setConent(hLayout);

    TextField tf = new TextField();
    hLayout.addComponent(tf);

要么按照评论中的建议使用 FormLayout 包装每个 TextBox,要么您必须更改 TextBox 的 css。将样式设置为您的 TextBox 以仅将其应用于您想要的样式。

TextBox yourTextBox = new TextBox();
yourTextBox.addStyleName("inline-label");

那么 css 将如下所示:

.v-caption-inline-label{
  display: inline-block;
}

为什么不这样做:

final FormLayout form = new FormLayout();

form.addComponent(new TextField("Caption line 1"));

final HorizontalLayout formLine2 = new HorizontalLayout();
formLine2.addComponents(new TextField(), new Button(), new Button());
formLine2.setCaption("Caption line 2");

第 1 行的文本字段保留了标题。 由于水平布局容器,第 2 行中的文本字段会将标题放在顶部。通过将标题从文本字段移动到水平布局,标题将再次位于左侧。