Changing theme on the fly

Starting from Vaadin 7.3, you can change themes in the application without reloading the page. To do this, simply use the UI.setTheme(String) method.

Java

  1. public class ThemeChangeUI extends UI {
  2. private String[] themes = { "valo", "reindeer", "runo", "chameleon" };
  3. @Override
  4. protected void init(VaadinRequest request) {
  5. ComboBox themePicker = new ComboBox("Theme", Arrays.asList(themes));
  6. themePicker.setValue(getTheme());
  7. themePicker.addValueChangeListener(new ValueChangeListener() {
  8. @Override
  9. public void valueChange(ValueChangeEvent event) {
  10. String theme = (String) event.getProperty().getValue();
  11. setTheme(theme);
  12. }
  13. });
  14. setContent(themePicker);
  15. }
  16. }

In this way, you can let your users choose the look of your application. The functionality also makes it easier to create applications that are branded for different customers.