GWT:如何将UiBinder xml布局添加到我的Widget? [英] GWT: How can I add UiBinder xml layout to my Widget?
问题描述
我有一个按钮,它是GWT PushButton
的直接后裔。我想将UiBInder xml布局添加到我的按钮以简化其设计。我创建了 MyButton.ui.xml
,并且我有以下内容 MyButton
:
I have a button which is a direct descendant of GWT PushButton
. I want to add UiBInder xml layout to my button to simplify its design. I have created MyButton.ui.xml
and I have the following contents of MyButton
:
class MyButton extends PushButton
{
interface UI extends UiBinder<Widget, MyButton>
{
}
private static final UI ui = GWT.create(UI.class);
@UiConstructor
public MyButton() {
super();
ui.createAndBindUi(this);
}
(...)
}
问题是我的按钮没有被渲染。 GWT创建一些div并将输入元素放置在里面,但是我在uibinder xml文件中创建的布局未应用。哪里出错了?
The problem is that my button is not rendered. GWT creates some div and places input element inside, but the layout I have created inside my uibinder xml file is not applied. Where I went wrong?
推荐答案
我不太确定,但是,可能是因为您没有实现asWidget( )方法:
I am not really sure, but, may be it's because you don't implement the asWidget() method:
@Override
public Widget asWidget() {
return widget;
}
小部件声明:
where widget is declared:
private final Widget widget;
并在您的构造函数中初始化为:
and initialized in you constructor as:
widget = ui.createAndBindUi(this);
希望这可以帮助您
这篇关于GWT:如何将UiBinder xml布局添加到我的Widget?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!