You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ChangingThemeOnTheFly.asciidoc 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. ---
  2. title: Changing Theme On The Fly
  3. order: 60
  4. layout: page
  5. ---
  6. [[changing-theme-on-the-fly]]
  7. Changing theme on the fly
  8. -------------------------
  9. Starting from Vaadin 7.3, you can change themes in the application
  10. without reloading the page. To do this, simply use the
  11. `UI.setTheme(String)` method.
  12. [source,java]
  13. ....
  14. public class ThemeChangeUI extends UI {
  15. private String[] themes = { "valo", "reindeer", "runo", "chameleon" };
  16. @Override
  17. protected void init(VaadinRequest request) {
  18. ComboBox themePicker = new ComboBox("Theme", Arrays.asList(themes));
  19. themePicker.setValue(getTheme());
  20. themePicker.addValueChangeListener(new ValueChangeListener() {
  21. @Override
  22. public void valueChange(ValueChangeEvent event) {
  23. String theme = (String) event.getProperty().getValue();
  24. setTheme(theme);
  25. }
  26. });
  27. setContent(themePicker);
  28. }
  29. }
  30. ....
  31. In this way, you can let your users choose the look of your application.
  32. The functionality also makes it easier to create applications that are
  33. branded for different customers.