Use ClientBundle image as background-image

半城伤御伤魂 提交于 2019-12-03 12:21:30
Stefan

In addition to Images, where you want to set the src property, you have to set

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

res is instantiated like this:

<!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>
....

and the client bundle looks like this:

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();

}

Creating the ClientBundle (with e.g. GWT.<TitleBarBundle>create(myRes.class);) wasn't necessary in my case.

Thanks for your answer Chris Boesing, but I felt like I had to share my experiences with you too.

Regards, Stefan

Here is how I do it. It is a little different than your approach but has worked great for me in this type of situation. Your ClientBundle would look like this:

public static interface PriceButtonStyles extends ClientBundle
{
     @Source("PriceButtonStyles.css")
     Styles priceButtonStyles();

     @Source("paid_button_53x31.png")
     ImageResource paidButtonPNG();

     interface Styles extends CssResource {
         String buttonBackground();
     }
}

Then you would need the PriceButtonStyles.css from the first @Source:

.buttonBackground {
    gwt-image:'paidButtonPNG';
    background-repeat:no-repeat;
}

Your *.ui.xml would look like this:

<ui:with field="res" type="com.ecample.client.PriceButton.PriceButtonStyles"></ui:with>
<g:Label styleName="{res.priceButtonStyles.buttonBackground}"><g:Label>

Even though your styles are in a css file it still gets minimized and obfuscated by the compiler.
Edit: Don't forget to call
GWT.<PriceButtonStyles> create(PriceButtonStyles.class).priceButtonStyles().ensureInjected(); Best place for this is your EntryPoint method

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