GWT StackLayoutPanel用法

在GWT StackLayoutPanel中, 一次仅垂直显示一个孩子。所有其他子窗口小部件将创建其标题并将其布置在面板底部。我们可以通过单击其标题查看子窗口小部件。
GWT StackLayoutPanel类声明
让我们看看com.google.gwt.user.client.ui.StackLayoutPanel的声明

public class StackLayoutPanel extends ResizeComposite

GWT StackLayoutPanel构造函数
建设者 描述
StackLayoutPanel(Style.Unit unit) 它创建一个空的堆栈面板。
StackLayoutPanel常用方法
修饰符和类型 方法 描述
void add(IsWidget widget, IsWidget header, double headerSize) 它是IsWidget的重载版本。
void add(Widget widget, SafeHtml header, double headerSize) 它将一个子小部件添加到此堆栈中, 同时还将一个小部件表示堆栈头。
void add(Widget widget, java.lang.String header, boolean asHtml, double headerSize) 它将一个子小部件添加到此堆栈中, 同时还将一个小部件表示堆栈头。
HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler < java.lang.Integer> 处理程序) 它添加一个BeforeSelectionEvent处理程序。
HandlerRegistration addSelectionHandler(SelectionHandler < java.lang.Integer> 处理程序) 它添加了SelectionEvent处理程序。
void animate(int duration) 其Layout子级, 在指定的时间段内进行动画处理。
void clear() 它删除所有子窗口小部件。
void forceLayout() 立即布置孩子。
widget getHeaderWidget(int index) 它在给定索引的堆栈头中获取小部件。
widget getHeaderWidget(Widget child) 它在与给定子控件关联的堆栈头中获取控件。
void insert(Widget child, SafeHtml html, double headerSize, int beforeIndex) 它将小部件插入面板。
void insert(Widget child, java.lang.String text, boolean asHtml, double headerSize, int beforeIndex) 它将小部件插入面板。
void setHeaderHTML(int index, java.lang.String html) 它设置堆栈头的HTML内容。
void setHeaderText(int index, java.lang.String text) 它设置堆栈头的文本内容。
void showWidget(Widget child) 它显示指定的窗口小部件并触发事件。
void showWidget(Widget child, boolean fireEvents) 它显示了指定的小部件。
GWT StackLayoutPanel示例1
//SampleStackLayoutPanel.java
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.gwtext.client.core.EventObject; import com.gwtext.client.widgets.Button; import com.gwtext.client.widgets.Panel; import com.gwtext.client.widgets.Window; import com.gwtext.client.widgets.event.ButtonListenerAdapter; import com.gwtext.client.widgets.layout.AccordionLayout; import com.gwtext.client.widgets.layout.HorizontalLayout; /*This is the entry point method. */ public void onModuleLoad() { // Create a three-item stack, with headers sized in EMs. StackLayoutPanel p = new StackLayoutPanel(Unit.EM); p.add(new HTML("First"), new HTML("[this]"), 4); p.add(new HTML("Second"), new HTML("[that]"), 4); p.add(new HTML("Many more"), new HTML("[Many more]"), 4); // Attach the StackLayoutPanelto the RootLayoutPanel. RootLayoutPanel rp = RootLayoutPanel.get(); rp.add(p); }

输出:
GWT StackLayoutPanel用法

文章图片
GWT StackLayoutPanel示例2
//SampleStackLayoutPanel.java
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.gwtext.client.core.EventObject; import com.gwtext.client.widgets.Button; import com.gwtext.client.widgets.Panel; import com.gwtext.client.widgets.Window; import com.gwtext.client.widgets.event.ButtonListenerAdapter; import com.gwtext.client.widgets.layout.AccordionLayout; import com.gwtext.client.widgets.layout.HorizontalLayout; public class StackLayoutSample implements EntryPoint {public void onModuleLoad() { Panel panel = new Panel(); panel.setBorder(false); panel.setPaddings(15); panel.setLayout(new HorizontalLayout(15)); Panel accordionPanel = createAccordionPanel(); accordionPanel.setTitle("Accordion Panel"); accordionPanel.setHeight(400); accordionPanel.setWidth(200); Button button = new Button("Show Accordion in Window", new ButtonListenerAdapter() { public void onClick(Button button, EventObject e) { Panel accordionPanel = createAccordionPanel(); Window window = new Window(); window.setTitle("Accordion Window"); window.setWidth(200); window.setHeight(400); window.add(accordionPanel); window.show(button.getId()); } }); panel.add(accordionPanel); panel.add(button); RootPanel.get().add(panel); }private Panel createAccordionPanel() { Panel accordionPanel = new Panel(); accordionPanel.setLayout(new AccordionLayout(true)); Panel panelOne = new Panel("Panel 1", "< p> Panel1 content!< /p> "); panelOne.setIconCls("settings-icon"); accordionPanel.add(panelOne); Panel panelTwo = new Panel("Panel 2", "< p> Panel2 content!< /p> "); panelTwo.setIconCls("folder-icon"); accordionPanel.add(panelTwo); Panel panelThree = new Panel("Panel 3", "< p> Panel3 content!< /p> "); panelThree.setIconCls("user-add-icon"); accordionPanel.add(panelThree); return accordionPanel; } }

//SampleStackLayoutPanel.css
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.RootPanel; import com.gwtext.client.core.EventObject; import com.gwtext.client.widgets.Button; import com.gwtext.client.widgets.Panel; import com.gwtext.client.widgets.Window; import com.gwtext.client.widgets.event.ButtonListenerAdapter; import com.gwtext.client.widgets.layout.AccordionLayout; import com.gwtext.client.widgets.layout.HorizontalLayout; public class StackLayoutSample implements EntryPoint {public void onModuleLoad() { Panel panel = new Panel(); panel.setBorder(false); panel.setPaddings(15); panel.setLayout(new HorizontalLayout(15)); Panel accordionPanel = createAccordionPanel(); accordionPanel.setTitle("Accordion Panel"); accordionPanel.setHeight(400); accordionPanel.setWidth(200); Button button = new Button("Show Accordion in Window", new ButtonListenerAdapter() { public void onClick(Button button, EventObject e) { Panel accordionPanel = createAccordionPanel(); Window window = new Window(); window.setTitle("Accordion Window"); window.setWidth(200); window.setHeight(400); window.add(accordionPanel); window.show(button.getId()); } }); panel.add(accordionPanel); panel.add(button); RootPanel.get().add(panel); }private Panel createAccordionPanel() { Panel accordionPanel = new Panel(); accordionPanel.setLayout(new AccordionLayout(true)); Panel panelOne = new Panel("Panel 1", "< p> Panel1 content!< /p> "); panelOne.setIconCls("settings-icon"); accordionPanel.add(panelOne); Panel panelTwo = new Panel("Panel 2", "< p> Panel2 content!< /p> "); panelTwo.setIconCls("folder-icon"); accordionPanel.add(panelTwo); Panel panelThree = new Panel("Panel 3", "< p> Panel3 content!< /p> "); panelThree.setIconCls("user-add-icon"); accordionPanel.add(panelThree); return accordionPanel; } }

【GWT StackLayoutPanel用法】输出:
GWT StackLayoutPanel用法

文章图片

    推荐阅读