Html contents in a vaadin label

两盒软妹~` 提交于 2019-12-12 20:19:15

问题


Is it possible to draw html contents in vaadin label?

I have texts with <br> contents. Is it available to let the label to use them?


回答1:


Yes, you can use the 2 argument constructor of Label and set the ContentMode to HTML.

Something like,

new Label(YOUR_HTML_TEXT, ContentMode.HTML);

From the Javadoc (linked above):

Label component for showing non-editable short texts. The label content can be set to the modes specified by ContentMode

The contents of the label may contain simple formatting:

  • Bold
  • Italic
  • Underlined
  • Linebreak
  • ...



回答2:


import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.Label;

Label htmlLabel = new Label("<h1>Header</h1><strike>text</strike>");
htmlLabel.setContentMode(ContentMode.HTML);

This piece of code shows needed classes and calls to have HTML markup rendered properly in a vaadin's Label.



来源:https://stackoverflow.com/questions/24491910/html-contents-in-a-vaadin-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!