如何使用GWT制作可水平扩展的StackPanel?

时间:2011-05-07 13:06:05

标签: java gwt

我是GWT的新手,有没有办法让StackPanel水平扩展或折叠?谢谢!!!

2 个答案:

答案 0 :(得分:2)

使用Horizo​​ntalSplitPanel并放入StackLayoutPanel。我创建了一个UIbinder类DockPanel。 Gwt为您创建一个与该类同名的xml文件。 DockPanel.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">
    <ui:style>
        .important { font-weight: bold;}
        .westPanel{background-color: #EEE;}
        .northPanel{background-color: #39F;
                border-width: 1px;
                border-style: solid;
                border-color: blue;}
             .h2 {color: #cacaca;
                 text-align: center;
                 font-family: Arial, Helvetica;
                 font-weight: bold;
                 font-size: 1.3em;}
        .southPanel{background-color: #99C;}
        .centerPanel{background-color: #FFC;}
        .botaoR{width: 120px; 
            height: 40px; 
            cursor: pointer;}
    </ui:style>

    <g:DockLayoutPanel unit='EM'>

        <g:north size='2'>
            <g:FlowPanel styleName="{style.northPanel}">
                <g:Label styleName="{style.h2}" text="Gestor de Horarios"/>
            </g:FlowPanel>
        </g:north>

<!-- Aqui foi inserido um StackPanel dentro do DockPanel tipo Acordeao -->
    <g:west size="15">
        <g:StackLayoutPanel unit='EM'>
            <g:stack>
                <g:header size='3'>
                    Docentes
                </g:header>
                    <g:Button styleName="{style.botaoR}" ui:field="botao" text="Ver Docentes" />
            </g:stack>
            <g:stack>
                <g:customHeader size='3'>
                    <g:Label>Cursos</g:Label>
                </g:customHeader>

                <g:VerticalPanel>
                    <g:Label>Exemplo </g:Label>
                    <g:Label>Exemplo </g:Label>
                    <g:Label>Exemplo </g:Label>
                    <g:Label>Exemplo </g:Label>
                </g:VerticalPanel>

            </g:stack>
            <g:stack>
                <g:customHeader size='3'>
                    <g:Label>Turmas</g:Label>
                </g:customHeader>
                    <g:Label>Mais uma turma para adicionar, olarilolela</g:Label>
            </g:stack>
        </g:StackLayoutPanel>
    </g:west>

        <g:center>
            <g:FlowPanel styleName="{style.centerPanel}">
                <g:Label>Painel Central</g:Label>
            </g:FlowPanel>
        </g:center>

        <g:south size ='2'>
            <g:FlowPanel styleName="{style.southPanel}">
                <g:Label>Painel de Rodape</g:Label>
            </g:FlowPanel>
        </g:south>

    </g:DockLayoutPanel>    
</ui:UiBinder>     

和我的 DockPanel.java()

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;


public class DockPanel extends Composite {

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

    interface DockPanelUiBinder extends UiBinder<Widget, DockPanel> {
    }

    @UiField Button botao;
    public DockPanel() {
        initWidget(uiBinder.createAndBindUi(this));

        //Botao para mostrar qq coisa
        botao.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                //Aqui coloquei um link, mas depois sera colocado uma accao
                Window.Location.assign("http://www.sapo.pt");   
            }
        });

    }

}    

上面的代码我使用 DockLayoutPanel ,但您可以使用

<g:HorizontalSplitPanel width="1024px" height="768px" splitPosition="200x" styleName="{style.resize-bar}">

...put here the code for StackLayoutPanel.... 
... create a css style for resize-bar

</g:HorizontalSplitPanel>    

试试吧

答案 1 :(得分:0)

我认为没有内置的水平堆栈面板,但您可以通过复制和修改现有StackPanel的代码来创建自己的堆栈面板。