您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TestForTabSheet.java 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.vaadin.tests;
  2. import com.vaadin.ui.Button;
  3. import com.vaadin.ui.Button.ClickEvent;
  4. import com.vaadin.ui.CustomComponent;
  5. import com.vaadin.ui.Label;
  6. import com.vaadin.ui.TabSheet;
  7. import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
  8. public class TestForTabSheet extends CustomComponent
  9. implements Button.ClickListener, TabSheet.SelectedTabChangeListener {
  10. TabSheet tabsheet = new TabSheet();
  11. Button tab1_root = new Button("Push this button");
  12. Label tab2_root = new Label("Contents of Second Tab");
  13. Label tab3_root = new Label("Contents of Third Tab");
  14. TestForTabSheet() {
  15. setCompositionRoot(tabsheet);
  16. tabsheet.addSelectedTabChangeListener(this);
  17. /* Listen for button click events. */
  18. tab1_root.addClickListener(this);
  19. tabsheet.addTab(tab1_root, "First Tab", null);
  20. /* A tab that is initially disabled. */
  21. tab2_root.setEnabled(false);
  22. tabsheet.addTab(tab2_root, "Second Tab", null);
  23. /* A tab that is initially disabled. */
  24. tab3_root.setEnabled(false);
  25. tabsheet.addTab(tab3_root, "Third tab", null);
  26. }
  27. @Override
  28. public void buttonClick(ClickEvent event) {
  29. System.out.println("tab2=" + tab2_root.isEnabled() + " tab3="
  30. + tab3_root.isEnabled());
  31. tab2_root.setEnabled(true);
  32. tab3_root.setEnabled(true);
  33. }
  34. @Override
  35. public void selectedTabChange(SelectedTabChangeEvent event) {
  36. /*
  37. * Cast to a TabSheet. This isn't really necessary in this example, as
  38. * we have only one TabSheet component, but would be useful if there
  39. * were multiple TabSheets.
  40. */
  41. TabSheet source = (TabSheet) event.getSource();
  42. if (source == tabsheet) {
  43. /* If the first tab was selected. */
  44. if (source.getSelectedTab() == tab1_root) {
  45. System.out.println("foo");
  46. tab2_root.setEnabled(false);
  47. tab3_root.setEnabled(false);
  48. }
  49. }
  50. }
  51. }