📜  GWT StackLayoutPanel(1)

📅  最后修改于: 2023-12-03 15:01:05.616000             🧑  作者: Mango

GWT StackLayoutPanel

Introduction

GWT StackLayoutPanel is a widget that allows you to create a stack of widgets, where only one widget is visible at a time. It behaves like a stack of cards, where each card can be flipped over to reveal the one beneath it.

This widget can be used to create tabbed interfaces, accordion menus, and other similar UI controls.

Features
  • Allows you to stack widgets on top of each other and switch between them.
  • Supports both vertical and horizontal orientations.
  • Supports header elements for each widget in the stack, which can be customized to suit your needs.
  • Provides methods to programmatically switch between widgets.
How to Use

To use StackLayoutPanel, you need to follow these steps:

  1. Create a StackLayoutPanel object:
StackLayoutPanel stackLayoutPanel = new StackLayoutPanel(Unit.PX);
  1. Add widgets to the StackLayoutPanel:
Widget widget1 = ...
String headerText1 = ...
stackLayoutPanel.add(widget1, new HTML(headerText1), 50);
  1. Repeat step 2 for all the widgets you want to add.
  2. Add the StackLayoutPanel to your user interface.
RootLayoutPanel.get().add(stackLayoutPanel);
  1. You can programmatically switch the visible widget using the following methods:
stackLayoutPanel.showWidget(int index);
stackLayoutPanel.showWidget(Widget widget);
Examples

Here's an example of how you can use StackLayoutPanel to create a simple accordion menu:

StackLayoutPanel stackLayoutPanel = new StackLayoutPanel(Unit.PX);

Widget content1 = new Label("Content 1");
String headerText1 = "Header 1";
stackLayoutPanel.add(content1, new HTML(headerText1), 50);

Widget content2 = new Label("Content 2");
String headerText2 = "Header 2";
stackLayoutPanel.add(content2, new HTML(headerText2), 50);

RootLayoutPanel.get().add(stackLayoutPanel);
Conclusion

GWT StackLayoutPanel is a powerful and versatile widget that can help you create rich and interactive UI controls. Its flexible API and rich feature set make it a great choice for building tabbed interfaces, accordion menus, and other similar UI patterns.