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

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