Skip to content

Instantly share code, notes, and snippets.

@amahdy
Created June 30, 2017 15:48
Show Gist options
  • Save amahdy/125ebe1c63a433565a359f2a76c9bf84 to your computer and use it in GitHub Desktop.
Save amahdy/125ebe1c63a433565a359f2a76c9bf84 to your computer and use it in GitHub Desktop.
Inject Style in Vaadin
package TEST;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.server.Page;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.UI;
import javax.servlet.annotation.WebServlet;
@Theme("mytheme")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
// Define the custom color
Color color = new Color(2,3,4);
// Inject a custom style
Page.Styles styles = Page.getCurrent().getStyles();
styles.add(".my-layout { background-color:" + color.getCSS() + "; }");
// Use the style
CssLayout cssLayout = new CssLayout();
cssLayout.addStyleName("my-layout");
cssLayout.setSizeFull();
setContent(cssLayout);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment