0

我有DisclosurePanel,作为标题内容,我有应用样式的 Horizo ​​ntalPanel,这些样式具有背景图像,它使用 ClientBundle 和 @sprite。但问题是样式不适用于标题小部件(水平面板)

我的代码在这里

入门级

public class Test implements EntryPoint {

    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
        TestClientBundle.INSTANCE.testCsss().ensureInjected();
        DisclosurePanel dp = new DisclosurePanel();
        HorizontalPanel hp = new HorizontalPanel();
        dp.setStyleName("blue");
        Label l = new Label("testing the DP with IMG-CSS bundle");
        hp.add(l);
        dp.setHeader(hp);
        dp.setContent(new Label("Body"));
        RootPanel.get().add(dp);
    }
}

ClientBundle 接口

public interface TestClientBundle extends ClientBundle {

    TestClientBundle INSTANCE = GWT.create(TestClientBundle.class);

    @Source("blue.jpg")
    public ImageResource blue();

    @Source("test.css")
    public CssResource testCsss();
}

CSS文件

@external .blue;
@sprite .blue {
    gwt-image: 'blue';
    cursor: pointer;
    text-decoration: none;
}

是 GWT 中的已知问题还是我的代码错误?

4

1 回答 1

0

代替

    dp.setStyleName("gates_playbookimage_blue");

您需要有一种方法来引用该 css 类名称 - 您需要一个CssResource接口:

public interface MyCssResource extends CssResource {
    String gates_playbookimage_blue();
}

从您的 clientbundle 而不是 CssResource 中引用它:

public interface TestClientBundle extends ClientBundle {
    TestClientBundle INSTANCE = GWT.create(TestClientBundle.class);

    @Source("playbook_blue.jpg")
    public ImageResource playbookBlue();

    @Source("test.css")
    public MyCssResource testCsss();
}

现在你可以这样做:

    MyCssResource css = TestClientBundle.INSTANCE.testCsss();
    css.ensureInjected();
    //...
    dp.setStyleName(css.gates_playbookimage_blue());

这将使 css 编译器根据需要重写您的 css,并确保将重写的类名传递给您的小部件。

于 2013-01-23T17:12:54.140 回答