Jam*_*ard 9 gwt flextable uibinder
我正在尝试使用uiBinder设置flextable.我正在使用GWT 2.4,我知道如何做一个flextable,但不是uiBinder.我发现了这个问题:如何在UiBinder中为GUI Web Toolkit添加行添加行?被问到了SO,但没有关于如何做到这一点的例子.
因此,如果我将小部件声明为:
@UiBinder FlexTable flexTable;
Run Code Online (Sandbox Code Playgroud)
如何使用uiBinder初始化一个空行,该行包含两列和一个用@UiConstructor或(provider = true)命名列的标题行?
小智 12
使用FlexTable小部件时,只能使用ui.xml模板来设置其位置,格式和属性.您仍然需要在Java代码中以实际方式提供表的内容(和标题).
有两种方法:
1:依靠模板在您调用时为您实例化一个新的空FlexTable initWidget(...).您可以立即跟进适当的电话table.setText(0,0, "Header 1")等,以指定您的内容.
2:在调用之前自己实例化FlexTable ,initWidget(...)并使用provided = true注释表成员变量.跟进相同的电话setText().
示例 (使用方法2)
public final class SomeWidget extends Composite {
@UiField (provided=true) FlexTable table;
SomeWidget() {
// When using provide=true, the table must be instantiated
// BEFORE calling initWidget.
setupTable();
initWidget(binder.createAndBindUi(this));
}
private void setupTable() {
table = new FlexTable();
table.setText(0, 0, "Header 1");
table.setText(0, 1, "Header 2");
// Create a temp blank row:
table.insertRow(1);
}
private static final Binder binder = GWT.create(Binder.class);
interface Binder extends UiBinder<Widget, SomeWidget> {}
}
Run Code Online (Sandbox Code Playgroud)
在你的ui.xml文件中:
<ui:UiBinder
xmlns:gwt="urn:import:com.google.gwt.user.client.ui"
xmlns:ui="urn:ui:com.google.gwt.uibinder">
<ui:style>
.table-style {
border: 1px solid black;
}
</ui:style>
<gwt:HTMLPanel>
Other random html
<gwt:FlexTable ui:field="table" styleName="{style.table-style}" borderWidth="2" />
</gwt:HTMLPanel>
</ui:UiBinder>
Run Code Online (Sandbox Code Playgroud)