【发布时间】: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 显示为格式化。
这是一张显示我的困境的图片。
任何帮助将不胜感激。
谢谢,
【问题讨论】: