Vaadin Web应用开发教程(34):UI布局-TabSheet布局

jerry VaadinWeb 2015年11月25日 收藏

TabSheet布局支持标签显示。TabSheet布局通过方法 addTab()添加一个标签页。

  1. // Create an empty tab sheet.
  2. TabSheet tabsheet = new TabSheet();
  3. // Make the tabsheet shrink to fit the contents.
  4. tabsheet.setSizeUndefined();
  5.  
  6. tabsheet.addTab(new Label("Contents of the first tab")).setCaption("first");
  7. tabsheet.addTab(new Label("Contents of the second tab")).setCaption("second");
  8. tabsheet.addTab(new Label("Contents of the third tab")).setCaption("third");

每个标签页为一Tab对象,可以显示标题和图标。

  1. tabsheet.addTab(new Label("Contents of the second tab"),
  2. "Second Tab",
  3. new ClassResource("images/Venus_small.png", this));

用户点击标签时触发TabSheet.SelectedTabChangeEvent事件,获取当前选中的标签的方法为getSelectedTab(),同样将某个标签设为当前页为setSelectedTab()。