我可以在 GWT 2.0 中混合声明式布局和编程式布局吗?

发布于 2024-08-16 04:59:44 字数 1936 浏览 3 评论 0原文

我正在尝试重做 GWT 2.0 发布之前制作的现有面板。该面板有几个文本字段和一个位于 VerticalPanel 下方的可滚动面板。

我想做的是使用 UIBinder 制作可滚动面板,然后将其添加到 VerticalPanel 下面是我创建的一个示例来说明这一点:

 public class ScrollTablePanel extends ResizeComposite{

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

     @UiField FlexTable table1;
     @UiField FlexTable table2;

     public Test2() {

      initWidget(uiBinder.createAndBindUi(this));



      table1.setText(0, 0, "testing 1");
      table1.setText(0, 1, "testing 2");
      table1.setText(0, 2, "testing 3");

      table2.setText(0, 0, "testing 1");
      table2.setText(0, 1, "testing 2");
      table2.setText(0, 2, "testing 3");
      table2.setText(1, 0, "testing 4");
      table2.setText(1, 1, "testing 5");
      table2.setText(1, 2, "testing 6");
     }
    }

然后是 xml:

<ui:UiBinder 
   xmlns:ui='urn:ui:com.google.gwt.uibinder' 
   xmlns:g='urn:import:com.google.gwt.user.client.ui'       
   xmlns:mail='urn:import:com.test.scrollpaneltest'>
       <g:DockLayoutPanel unit='EM'>
      <g:north size="2">
       <g:FlexTable ui:field="table1"></g:FlexTable>
      </g:north>
      <g:center>
       <g:ScrollPanel>
         <g:FlexTable ui:field="table2"></g:FlexTable>
       </g:ScrollPanel>
      </g:center>
    </g:DockLayoutPanel>
</ui:UiBinder>

然后在 EntryPoint 中执行类似的操作:

 public void onModuleLoad() {

     VerticalPanel vp = new VerticalPanel();
     vp.add(new ScrollTablePanel());
     vp.add(new Label("dummy label text"));
     vp.setWidth("100%");

     RootLayoutPanel.get().add(vp);
    }

但是当我添加ScrollTablePanel 到 VerticalPanel,页面上只有第一个 FlexTable(test1)可见,而不是整个 ScrollTablePanel。

有没有办法让这项工作能够在 GWT 2.0 中混合声明式布局和程序式布局?

I'm trying to redo an existing panel that I made before GWT 2.0 was released. The panel has a few text fields and a scrollable panel below in a VerticalPanel.

What I'd like to do is to make the scrollable panel with UIBinder and then add that to a VerticalPanel Below is an example I created to illustrate this:

 public class ScrollTablePanel extends ResizeComposite{

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

     @UiField FlexTable table1;
     @UiField FlexTable table2;

     public Test2() {

      initWidget(uiBinder.createAndBindUi(this));



      table1.setText(0, 0, "testing 1");
      table1.setText(0, 1, "testing 2");
      table1.setText(0, 2, "testing 3");

      table2.setText(0, 0, "testing 1");
      table2.setText(0, 1, "testing 2");
      table2.setText(0, 2, "testing 3");
      table2.setText(1, 0, "testing 4");
      table2.setText(1, 1, "testing 5");
      table2.setText(1, 2, "testing 6");
     }
    }

then the xml:

<ui:UiBinder 
   xmlns:ui='urn:ui:com.google.gwt.uibinder' 
   xmlns:g='urn:import:com.google.gwt.user.client.ui'       
   xmlns:mail='urn:import:com.test.scrollpaneltest'>
       <g:DockLayoutPanel unit='EM'>
      <g:north size="2">
       <g:FlexTable ui:field="table1"></g:FlexTable>
      </g:north>
      <g:center>
       <g:ScrollPanel>
         <g:FlexTable ui:field="table2"></g:FlexTable>
       </g:ScrollPanel>
      </g:center>
    </g:DockLayoutPanel>
</ui:UiBinder>

Then do something like this in the EntryPoint:

 public void onModuleLoad() {

     VerticalPanel vp = new VerticalPanel();
     vp.add(new ScrollTablePanel());
     vp.add(new Label("dummy label text"));
     vp.setWidth("100%");

     RootLayoutPanel.get().add(vp);
    }

But when I add the ScrollTablePanel to the VerticalPanel, only the first FlexTable (test1) is visible on the page, not the whole ScrollTablePanel.

Is there a way to make this work where it is possible to mix declarative and programmatic layout in GWT 2.0?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呆头 2024-08-23 04:59:44

你绝对可以,尽管它有点违背了使用 uiBinder 的初衷。当然,当您必须使用动态 gui 元素(例如 FlexTable)时,您无法避免初始化代码,但您仍然可以使用 @UiFactory 和 @UiField(provided=true) 来避免其中的一些代码。
我相信您的问题与容器 VerticalPanel 的大小有关,请尝试将其设置为 100%。

You definetely can, although it kind of beats the purpose of using uiBinder in the first place. Of course when you have to use dymamic gui elements, such as FlexTable, you can't avoid init code but still you can use @UiFactory and @UiField(provided=true) to avoid some of it.
I believe your problem has to do with the size of the container VerticalPanel, try setting it to 100%.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文