带换行符的GWT标签 [英] GWT label with line breaks
问题描述
GWT标签小部件iterprets一切为文本,而不是html标签 - 这很好,但我希望它解释 \\\
为
我会创建子类,但无法找到要重写的内容来实现此行为
(我可以使用HTML小部件,但它会解释所有标签 - 而我需要的只是一个线性布拉克)
使用一个HTML小部件并使用 SafeHtml 设置其值,使用 SafeHtmlBuilder.appendEscapedLines
:
HTML标签=新的HTML(新的SafeHtmlBuilder()。 appendEscapedLines( 富< bar\\\
baz> QUUX)。toSafeHtml());
(或者,您可以 split(\\\
您的文本,在每个部分上调用
,-1 ) SafeHtml.htmlEscape
,然后将它们加回到< br>
,这就是 appendEscapedLines
)
GWT Label widgets iterprets everything as text, not as html tags - that's good, but I would like it to interpret \n
as a <br />
how do i do that.
I would make subclass, but I cant find what to override to achieve this behaviour
(I could use HTML widget, but it would interpret all tags - and all I need is an line brak)
Use an HTML widget and set its value using a SafeHtml
constructed with SafeHtmlBuilder.appendEscapedLines
:
HTML label = new HTML(new SafeHtmlBuilder().appendEscapedLines("foo<bar\nbaz>quux").toSafeHtml());
(alternatively, you can split("\n", -1)
your text, call SafeHtml.htmlEscape
on each part and join them back with a <br>
, that's what appendEscapedLines
does)
这篇关于带换行符的GWT标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!