简体   繁体   English

GWT中的基本面板嵌套

[英]Basic Panel nesting in GWT

Following nesting of Basic Panel is possible in GWT ? 在GWT中可以嵌套基本面板吗?

<g:HTMLPanel>
     <g:HTMLPanel>
      .......
     </g:HTMLPanel>
  <g:ScrollPanel>
     <g:HTMLPanel>
      ........  
     </g:HTMLPanel>
  </g:ScrollPanel>
</g:HTMLPanel> 

My Problem is I need to scroll second HTML Panel. 我的问题是我需要滚动第二个HTML面板。 My UIBinder will be containing two children HTMLPanels under a parent HTMLPanel. 我的UIBinder将在父HTMLPanel下包含两个子HTMLPanel。 But I need second htmlpanel scroll-able. 但我需要第二个htmlpanel可滚动。

I just created a new GWT project and 我刚刚创建了一个新的GWT项目,

UiBinder file: UiBinder文件:

 <!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">
    <ui:style>
    .important {
        font-weight: bold;
    }
    </ui:style>
    <g:HTMLPanel>
        <g:HTMLPanel>
        First panel
    </g:HTMLPanel>
    <g:ScrollPanel height="100px">
    <g:HTMLPanel>
            aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>
            aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>
            aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>
            aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaaaaaaa<br/>
    </g:HTMLPanel>
    </g:ScrollPanel>
    </g:HTMLPanel>

</ui:UiBinder> 

And Java file 和Java文件

public class RetaTest extends Composite implements HasText {

    private static RetaTestUiBinder uiBinder = GWT
            .create(RetaTestUiBinder.class);

    interface RetaTestUiBinder extends UiBinder<Widget, RetaTest> {
    }

    public RetaTest() {
        initWidget(uiBinder.createAndBindUi(this));
    }


    public RetaTest(String firstName) {
        initWidget(uiBinder.createAndBindUi(this));
    }


    @Override
    public String getText() {
        // TODO Auto-generated method stub
        return null;
    }


    @Override
    public void setText(String text) {
        // TODO Auto-generated method stub

    }

}

And onModuleLoad 和onModuleLoad

  public void onModuleLoad() {

    RootPanel.get().add(new RetaTest());
  }

It works. 有用。 TestPicture

There are panels in GWT that take their size from their parents and/or provide size to their children. GWT中有一些小组可以根据其父母的意见和/或为他们的孩子提供意见。 For example, when you add HTMLPanel to the RootPanel, the RootPanel provides its own size (equal to the browser view) to this HTMLPanel. 例如,当您将HTMLPanel添加到RootPanel时,RootPanel会为此HTMLPanel提供其自己的大小(等于浏览器视图)。

HTMLPanel, however, does not implement ProvidesResize() interface. 但是,HTMLPanel不实现ProvidesResize()接口。 So, when you add another HTMLPanel and a ScrollPanel to it, these panels have initial height of zero. 因此,当您向其添加另一个HTMLPanel和ScrollPanel时,这些面板的初始高度为零。 After that these panels take their height from their own children. 之后,这些小组将自己的孩子带到自己的高度。

This means that your ScrollPanel will continue to expand as you add more content to it, and it will never start scrolling. 这意味着您向ScrollPanel添加更多内容时将继续扩展,并且永远不会开始滚动。 You have two options to fix this. 您有两个解决方案。

First, you can set a height on ScrollPanel (ie height="100px"). 首先,您可以在ScrollPanel上设置一个高度(即height =“ 100px”)。

Second, you can use a LayoutPanel instead of HTMLPanel as a container for your view, and add HTMLPanel and ScrollPanel to different layers of this LayoutPanel. 其次,您可以使用LayoutPanel而不是HTMLPanel作为视图的容器,然后将HTMLPanel和ScrollPanel添加到此LayoutPanel的不同层。 Each layer provides a size to its child. 每层为其子级提供大小。

In both cases your ScrollPanel will have a specified height (in pixels, percents, ems, etc.) Therefore, it will start scrolling once the height of its children exceeds its own height. 在这两种情况下,您的ScrollPanel都将具有指定的高度(以像素,百分比,ems等为单位)。因此,一旦其子代的高度超过其自身的高度,它将开始滚动。

Fix the width of scroll panel, but do not fix the width for its children HTML panel. 固定滚动面板的宽度,但不固定其子HTML面板的宽度。 Then it should work. 然后它应该工作。 Nothing is problem in your code, except fixing the width properties accordingly. 除了相应地固定width属性之外,您的代码中没有任何问题。

This is just exact solution to your problem. 这只是您问题的精确解决方案。 But to understand some what beyond this read the first answer given by Andrevi Glovin. 但是要了解其他内容,请阅读Andrevi Glovin给出的第一个答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM