List of usage examples for com.vaadin.ui Button setIcon
public void setIcon(Resource icon, String iconAltText)
From source file:eu.maxschuster.vaadin.buttonlink.demo.DemoUI.java
License:Apache License
@Override protected void init(VaadinRequest request) { final VerticalLayout wrapper = new VerticalLayout(); wrapper.setSizeFull();//from w w w .ja v a 2s .co m setContent(wrapper); // Show it in the middle of the screen final VerticalLayout layout = new VerticalLayout(); layout.setSpacing(true); layout.setSizeUndefined(); wrapper.addComponent(layout); wrapper.setComponentAlignment(layout, Alignment.MIDDLE_CENTER); final Label themeName = new Label(); themeName.setCaption("Current Theme:"); themeName.addStyleName("h1"); layout.addComponent(themeName); Label waring = new Label("<strong>Attention:</strong><br />\nChanging the theme may take a few seconds!"); waring.setContentMode(ContentMode.HTML); layout.addComponent(waring); getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { @Override public void uriFragmentChanged(UriFragmentChangedEvent event) { String fragment = event.getUriFragment().replace("!", ""); if (fragment.isEmpty()) { fragment = defaultTheme; } loadTheme(fragment); } }); themeSelect.setSizeFull(); themeSelect.setNullSelectionAllowed(false); themeSelect.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { String fragment = "!" + themeSelect.getValue(); getPage().setUriFragment(fragment); } }); layout.addComponent(themeSelect); layout.setComponentAlignment(themeSelect, Alignment.BOTTOM_CENTER); final CheckBox useIcon = new CheckBox("Use icons"); useIcon.setValue(false); layout.addComponent(useIcon); final HorizontalLayout comparsionLayout = new HorizontalLayout(); comparsionLayout.setSpacing(true); layout.addComponent(comparsionLayout); layout.setComponentAlignment(comparsionLayout, Alignment.TOP_CENTER); final Button button = new Button("This is a \"normal\" Button", new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { Notification.show("Hello World!"); } }); comparsionLayout.addComponent(button); comparsionLayout.setComponentAlignment(button, Alignment.MIDDLE_RIGHT); // Initialize our new UI component final ButtonLink buttonLink = new ButtonLink("This is a ButtonLink", new ExternalResource("https://vaadin.com")); buttonLink.setTargetName("_blank"); buttonLink.setDescription("Visit vaadin.com in a new tab or window."); buttonLink.addStyleName("test-stylename"); comparsionLayout.addComponent(buttonLink); comparsionLayout.setComponentAlignment(buttonLink, Alignment.MIDDLE_LEFT); themeName.setPropertyDataSource(themeSelect); useIcon.addValueChangeListener(new ValueChangeListener() { @Override public void valueChange(ValueChangeEvent event) { boolean b = (Boolean) event.getProperty().getValue(); if (b) { button.setIcon(vaadinIcon, "Vaadin Logo"); buttonLink.setIcon(vaadinIcon, "Vaadin Logo"); } else { button.setIcon(null); buttonLink.setIcon(null); } } }); String fragment = getPage().getUriFragment(); loadTheme( fragment == null || fragment.replace("!", "").isEmpty() ? defaultTheme : fragment.replace("!", "")); }