Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java vaadin标签文本未换行_Java_Vaadin_Vaadin7 - Fatal编程技术网

Java vaadin标签文本未换行

Java vaadin标签文本未换行,java,vaadin,vaadin7,Java,Vaadin,Vaadin7,正如罐头上写的。。我无法获取要包装的标签文本。本质上,我像一个评论面板一样构建,用户输入一条评论,并用时间戳等显示它 我希望标签既显示为ContentMode.PREFORMATTED,又显示为wrap 包含标签的布局是固定宽度的(100%),因为标签在默认情况下是固定宽度的,根据我在瓦丁书中读到的,我正在做什么应该有效 以下是我的代码片段: VerticalLayout container = new VerticalLayout(); rootLayout.addComponent(cont

正如罐头上写的。。我无法获取要包装的标签文本。本质上,我像一个评论面板一样构建,用户输入一条评论,并用时间戳等显示它

我希望标签既显示为
ContentMode.PREFORMATTED
,又显示为wrap

包含标签的布局是固定宽度的(100%),因为标签在默认情况下是固定宽度的,根据我在瓦丁书中读到的,我正在做什么应该有效

以下是我的代码片段:

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
显示为格式化,如果用户自己在单独的行中输入文本,如果他们输入了长段落注释,则显示为换行

这是一幅我左右为难的图画

任何帮助都将不胜感激

谢谢,

试试css。 例如:

textLbl.addStyleName("wrapLine");
Css:


使用css:我尝试应用建议的解决方案。这对我来说不起作用,因为单词包装被另一种样式停用了,这种样式在宽度未定义时应用。所以对我来说,解决方案就是简单地使用textLbl.setWidth(“100%”);
.wrapLine{
   word-wrap: break-word; /* IE  */
   white-space: -moz-pre-wrap; /* Firefox */
}