2014-09-23 161 views
1

因爲它在錫說..我不能讓一個標籤的文本換行。基本上我正在建設像一個評論面板,用戶輸入一個評論,並顯示與時間戳等vaadin標籤文本不換

我希望標籤既顯示ContentMode.PREFORMATTED,但也包裝。

其中包含標籤的佈局是固定的寬度(100%)是明顯的標籤在默認情況下,從我看書vaadin我在做什麼應該工作的書嗎?

這裏是我的代碼片段:

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顯示爲格式,如果用戶在單獨的行上輸入文本,並在輸入長段註釋時進行換行。

這裏是在我的窘境生動描述。

example

任何幫助,將不勝感激。

謝謝,

+1

使用CSS:http://css-tricks.com/almanac/properties/o/overflow/ – riddy 2014-09-23 09:21:32

回答

1

嘗試使用CSS。 例如:

textLbl.addStyleName("wrapLine"); 

定製CSS:

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