如何在gwt uibinder中添加图像

时间:2014-07-10 07:36:05

标签: gwt

我在gwt中有一个UIBinder java类,它包含一些带有一些文本的标签,如

 Label img = new Label();
 img.setText("<img src=h.png></img>") or some other Html tag like div

并在HTMLPanel中添加此标签

HTMLPanel html = new HTMLPanel;
html.add(img,"img");

现在我在uibinder xml中有一个像

的表
 <table align="center" cellspacing="20px">
                        <tr>
                            <td>image</td>
                            <td id="image"></td>
                        </tr>
    <table>

但是我在这里得到一个字符串

"<img src=h.png></img>"

不是形象,请有人帮助我..

1 个答案:

答案 0 :(得分:5)

如果需要图像,则无需使用Label小部件。如果您使用ImageResource,则可以执行以下操作:

// Link to your ClientBundle with ImageResource methods
<ui:with type="com.myPackage.client.icons.Icons" field="icon" />

<g:Image ui:field="myImage" resource="{icon.myImage}" />

如果您不需要此图片来执行任何操作,那么您只需使用常规HTML:

<g:HTMLPanel>
    <img src="h.png" />
</g:HTMLPanel>