Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.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 如何插入<;b>;GWT标签中的元素_Java_Html_Gwt - Fatal编程技术网

Java 如何插入<;b>;GWT标签中的元素

Java 如何插入<;b>;GWT标签中的元素,java,html,gwt,Java,Html,Gwt,我正在使用GWT UiBinder,我想创建以下标签 -------------------------------------------- 您只能上载.jpg图像 -------------------------------------------- 因此,我的问题是如何在标签中插入html元素,或者您可以提供其他解决方案,使GWT标签中的文本加粗。您可以使用SafeHtmlBuilder类实现这一点。你告诉它你想转义的字符串和你不想转义的字符串。它的工作原理类似于StringBuilde

我正在使用GWT UiBinder,我想创建以下标签

--------------------------------------------

您只能上载.jpg图像

--------------------------------------------


因此,我的问题是如何在标签中插入html元素,或者您可以提供其他解决方案,使GWT标签中的文本加粗。

您可以使用
SafeHtmlBuilder
类实现这一点。你告诉它你想转义的字符串和你不想转义的字符串。它的工作原理类似于
StringBuilder
,因为您调用了append方法

类似的答案请参考链接: 使用小部件而不是标签小部件:

<g:HTML ui:field="imgInfo">You can upload only <b>.jpg</b> images</g:HTML>
您只能上载.jpg图像

philfr49绝对正确。标签使用createTextNode,不能使用HTML。如果您仍然想这样做,您可以这样做:

DirectionalTextHelper directionalTextHelper = new DirectionalTextHelper(imgInfo.getElement(), true);
directionalTextHelper.setTextOrHtml("You can upload only <b>.jpg</b>; images", true);
DirectionalTextHelper DirectionalTextHelper=新的DirectionalTextHelper(imgInfo.getElement(),true);
directionalTextHelper.setTextOrHtml(“您只能上载.jpg;图像”,true);
更新:
HTML(class=“gwt HTML”)和Label(class=“gwt Label”)都生成DIV元素作为包装器元素。这两个类在standard.css中都是空的。因此,请选择适合您的方法

您可以改用DOM元素

@UiField
Element myLabel;

public void setLabelText(String text)
{
    myLabel.setInnerHTML(new SafeHtmlBuilder().appendEscaped(text).toSafeHtml().asString());
}
yourlab.getElement().setInnerHTML(“您只能上载.jpg图像”);如果您想要内联标签(似乎是默认值),
InlineHTML
可能更适合,因为它会生成一个
标记,而不是
DirectionalTextHelper directionalTextHelper = new DirectionalTextHelper(imgInfo.getElement(), true);
directionalTextHelper.setTextOrHtml("You can upload only <b>.jpg</b>; images", true);
@UiField
Element myLabel;

public void setLabelText(String text)
{
    myLabel.setInnerHTML(new SafeHtmlBuilder().appendEscaped(text).toSafeHtml().asString());
}