gpt4 book ai didi

gwt - 使用ClientBundle图像作为背景图像

转载 作者:行者123 更新时间:2023-12-04 03:46:15 25 4
gpt4 key购买 nike

我正在尝试将ClientBundle中的图像用作UIBInder模板中的背景图像。我使用this discussion作为指南,但无法使其正常工作。

在我的Java课中,我有:

public static interface PriceButtonStyles extends ClientBundle
{
String paidIcon();

@ClientBundle.Source("paid_button_53x31.png")
DataResource paid_buttonAsDataResource();
}

@UiField
PriceButtonStyles priceButtonStyle;

然后在相应的模板文件中像这样引用它:
<ui:style field="priceButtonStyle" type="com.example.client.PriceButton.PriceButtonStyles">

@url paidIconUrl paid_buttonAsDataResource;

.paidIcon {
background: paidIconUrl 0 0 no-repeat;

}
</ui:style>

至此,我的IDE已经以红色显示“paidIconUrl”字符串,表明有些不正确:

确实,当我尝试运行它时,我得到:
    ERROR: Type com.ecample.client.PriceButton.PriceButtonStyles does not extend com.google.gwt.resources.client.CssResource Element <ui:style field='priceButtonStyle' type='com.example.client.PriceButton.PriceButtonStyles'> (:7). 
ERROR: Uncaught exception escaped. com.google.gwt.event.shared.UmbrellaException: One or more exceptions caught, see full set in UmbrellaException#getCauses

进一步在 Google Groups discussion中,建议这可能与 <ui:data>一起使用,而不是 <ui:style>,所以我尝试使其工作。但是似乎您不能在 paidIcon()资源中同时包含CSS样式(例如我的 <ui:data>方法)和DataResources。我找不到关于 <ui:data>的很多文档,所以我真的只是在捕获这个问题。

最佳答案

除了图像外,您还需要在其中设置src属性。

<g:Image url="{res.minimize.getSafeUri.asString}" ....>

res实例化如下:
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui">

<ui:with field="res"
type="xxx.myRes"></ui:with>
....

客户端捆绑看起来像这样:
package xxx;

import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;

public interface myRes extends ClientBundle {

@Source("minimize.png")
ImageResource minimize();

}

在我的情况下,无需创建ClientBundle(例如 GWT.<TitleBarBundle>create(myRes.class);)。

感谢您的回答克里斯·波辛(Chris Boesing),但我感到我也必须与您分享我的经验。

问候,
斯特凡

关于gwt - 使用ClientBundle图像作为背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5354347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com