【问题标题】:vaadin label text not wrappingvaadin 标签文本不换行
【发布时间】:2016-08-19 00:36:05
【问题描述】:

正如罐头上所说的那样。我无法让标签的文本换行。本质上,我正在构建一个 cmets 面板,用户输入评论并显示时间戳等。

我希望标签既能用ContentMode.PREFORMATTED 显示,又能换行。

包含标签的布局是固定宽度(100%),显然默认情况下标签也是如此,从我在 vaadin 的书中读到的内容,我正在做什么应该工作?

这是我的代码 sn-p:

VerticalLayout container = new VerticalLayout();
rootLayout.addComponent(container);

VerticalLayout comment = new VerticalLayout();
container.addComponent(comment);

Label createdByLbl = new Label(entity.getManagedMetadata().getAttrValue("createdBy") + " said:");
createdByLbl.setId("conversation.comment.username." + repositoryUID);
createdByLbl.setStyleName("conversation-comment-username");

Label createdDateLbl = new Label(entity.getManagedMetadata().getAttrValue("createdDate"));
createdDateLbl.setId("conversation.comment.createddate." + repositoryUID);
createdDateLbl.setSizeUndefined();

String text = entity.getDataNode().getAttrValue("text");
Label textLbl = new Label(text, ContentMode.PREFORMATTED);
textLbl.setId("conversation.comment.text." + repositoryUID);

comment.addComponent(createdByLbl);
comment.addComponent(textLbl);
comment.addComponent(createdDateLbl);

comment.setExpandRatio(createdByLbl, 0.2f);
comment.setExpandRatio(textLbl, 0.7f);
comment.setExpandRatio(createdDateLbl, 0.1f);

注意容器也被 CssLayout (rootLayout) 包裹,它是全尺寸的。

如果用户自己在单独的行中输入文本并在输入长段落注释时换行,我希望上面看到的textLbl 显示为格式化。

这是一张显示我的困境的图片。

任何帮助将不胜感激。

谢谢,

【问题讨论】:

标签: java vaadin vaadin7


【解决方案1】:

尝试使用 css。 例如:

textLbl.addStyleName("wrapLine");

CSS:

.wrapLine{
   word-wrap: break-word; /* IE  */
   white-space: -moz-pre-wrap; /* Firefox */
}

【讨论】:

  • 我尝试应用建议的解决方案。它对我不起作用,因为换行已被另一种样式停用 - 当宽度未定义时应用的样式。所以对我来说,解决方案是简单地使用 textLbl.setWidth("100%");
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
  • 1970-01-01
  • 2018-06-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多