我在使用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>
最佳答案
所有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