Accordion

Live Demo

Accordion is a multicomponent container similar to TabSheet, except that the “tabs” are arranged vertically. Clicking on a tab opens its contained component in the space between the tab and the next one. You can use an Accordion identically to a TabSheet, which it actually inherits. See “TabSheet” for more information.

The following example shows how you can create a simple accordion. As the Accordion is rather naked alone, we put it inside a Panel that acts as its caption and provides it a border.

Java

  1. // Create the accordion
  2. Accordion accordion = new Accordion();
  3. // Create the first tab, specify caption when adding
  4. Layout tab1 = new VerticalLayout(); // Wrap in a layout
  5. tab1.addComponent(new Image(null, // No component caption
  6. new ThemeResource("img/planets/Mercury.jpg")));
  7. accordion.addTab(tab1, "Mercury",
  8. new ThemeResource("img/planets/Mercury_symbol.png"));
  9. // This tab gets its caption from the component caption
  10. Component tab2 = new Image("Venus",
  11. new ThemeResource("img/planets/Venus.jpg"));
  12. accordion.addTab(tab2).setIcon(
  13. new ThemeResource("img/planets/Venus_symbol.png"));
  14. // And so forth the other tabs...
  15. String[] tabs = {"Earth", "Mars", "Jupiter", "Saturn"};
  16. for (String caption: tabs) {
  17. String basename = "img/planets/" + caption;
  18. VerticalLayout tab = new VerticalLayout();
  19. tab.addComponent(new Image(null,
  20. new ThemeResource(basename + ".jpg")));
  21. accordion.addTab(tab, caption,
  22. new ThemeResource(basename + "_symbol.png"));
  23. }

An Accordion shows what the example would look like with the default theme.

accordion example1

An Accordion

CSS Style Rules

CSS

  1. .v-accordion {}
  2. .v-accordion-item,
  3. .v-accordion-item-open,
  4. .v-accordion-item-first {}
  5. .v-accordion-item-caption {}
  6. .v-caption {}
  7. .v-accordion-item-content {}
  8. .v-scollable {}

The top-level element of Accordion has the v-accordion style. An Accordion consists of a sequence of item elements, each of which has a caption element (the tab) and a content area element.

The selected item (tab) has also the v-accordion-open style. The content area is not shown for the closed items.