使用StackLayoutPanel时出现问题

时间:2011-03-25 12:07:45

标签: java gwt uibinder

我在使用StackPanel布局时遇到问题。这是行不通的。它只显示标题但没有标签。即使文档中的示例也不起作用:

http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/StackLayoutPanel.html

的java:

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Widget;

public class NavigationWidget extends Composite implements HasText {

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

    interface NavigationWidgetUiBinder extends
            UiBinder<Widget, NavigationWidget> {
    }

    public NavigationWidget() {
        initWidget(uiBinder.createAndBindUi(this));

    }

    public void setText(String text) {
    }

    public String getText() {
        return null;
    }

}

的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">

    <g:HTMLPanel>
        <g:StackLayoutPanel unit='PX'>

            <g:stack>
                <g:header size='30'>
                    People
                </g:header>
                <g:VerticalPanel>
                    <g:Label>People Item 1</g:Label>
                    <g:Label>People Item 2</g:Label>
                    <g:Label>People Item 3</g:Label>
                    <g:Label>People Item 4</g:Label>
                </g:VerticalPanel>
            </g:stack>

            <g:stack>
                <g:header size='30'>
                    Groups  
                </g:header>
                <g:VerticalPanel>
                    <g:Label>Group Item 1</g:Label>
                    <g:Label>Group Item 2</g:Label>
                    <g:Label>Group Item 3</g:Label>
                    <g:Label>Group Item 4</g:Label>
                </g:VerticalPanel>
            </g:stack>

            <g:stack>
                <g:header size='30'>
                    Settings
                </g:header>
                <g:VerticalPanel>
                    <g:Label>Item 5</g:Label>
                    <g:Label>Item 6</g:Label>
                    <g:Label>Item 7</g:Label>
                    <g:Label>Item 8</g:Label>
                </g:VerticalPanel>
            </g:stack>

        </g:StackLayoutPanel>

    </g:HTMLPanel>
</ui:UiBinder> 

1 个答案:

答案 0 :(得分:4)

所有LayoutPanel必须位于实现ProvidesResize的容器中,或者在代码中明确设置其大小。最简单的方法是明确设置StackLayoutPanel的大小:只需将height="100%"添加到<StackLayoutPanel>元素即可。

要获得更多控制权,请将Composite基类更改为ResizeComposite并删除<g:HTMLPanel>元素 - 只需将StackLayoutPanel作为ui.xml文件的根元素即可。您还必须确保仅在其他NavigationWidget中使用LayoutPanel - 例如,您不会将其添加到RootPanel.get(),而是添加到RootLayoutPanel.get() }

有关详细信息,请参阅http://code.google.com/webtoolkit/doc/latest/DevGuideUiPanels.html