java - 试图让 GWT DataGrid 在 UiBinder 中工作

标签 java gwt datagrid uibinder

我正在尝试掌握 GWT 中 UI Binder 的窍门。

到目前为止,我已经有了一个基本的应用程序来显示带有一些示例数据的 DataGrid,它可以在传统的 GWT 和 UIBinder 之间轻松切换。它在传统 GWT 中正常工作,但在 UiBinder 中不正常。

这是主要的 EntryPoint 类:

public class Main implements EntryPoint {

  public void onModuleLoad() {

        uiBinder(); //call either uiBinder() or gwt() here
  }

  /* Use UiBinder to display grid */
  public void uiBinder() {
        HelloWorld hello = new HelloWorld();
        RootPanel.get("myid").add(hello);
  }

  /* Use traditional GWT to display grid */
  public void gwt() {
        DataGrid<Contact> grid = new DataGrid<Contact>();
        GridInitializer.init(grid);
        RootLayoutPanel.get().add(grid);
  }

}

这是 UiBinder 使用的 HelloWorld.java:

public class HelloWorld extends Composite {

  interface MyUiBinder extends UiBinder<Widget, HelloWorld> {}
  private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

  @UiField DataGrid<Contact> grid;

  public HelloWorld() {            
        GridInitializer.init(grid);
        initWidget(uiBinder.createAndBindUi(this));
  }
}

GridInitializer 类设置网格列和示例数据。我没有任何问题,因为如果我使用传统的 GWT,它可以正确呈现。

这是 HelloWorld.ui.xml:

<!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'
  xmlns:c="urn:import:com.google.gwt.user.cellview.client">

  <g:DockLayoutPanel unit="EM">
    <g:center>
      <c:DataGrid ui:field='grid' />
    </g:center>
  </g:DockLayoutPanel>

</ui:UiBinder>

如果我使用 UI Binder,则根本不会显示任何内容。我不知所措。有什么建议吗?

最佳答案

DataGrid(RequireSize 小部件)必须添加到(必须是其子项)ProvidesResize面板/小部件,否则必须明确调整大小。

因此,您必须设置 DataGrid 或其父组件的大小。此外,它要求您的应用程序使用 RootLayoutPanel .

关于java - 试图让 GWT DataGrid 在 UiBinder 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19252161/

相关文章:

java - 使用 FXML 文件中创建的 TableView 填充 JavaFX 中的 TableView

java - 在 selenium webdriver (Java) 中查找嵌套元素

java - 无法运行 cucumber 测试 - java.lang.NoSuchMethodError : cucumber. runtime.Runtime.<init>

java - GAE 用户 + OpenId + Oauth2 Java

java - gwt setEnabled 未在 GoogleChrome 上执行

使用控制台处理程序以生产模式登录 GWT

c# - DbSet 和 ObservableCollection 之间的转换

java - 从头开始设计大型 Java webapp 的建议

方向改变时 Android TableLayout 重复

c# 将行添加到数据网格组合框