GWT override css from theme









  • Create css file in com/myapp/client/resource/myapp.css:
    • body, table td, select {
        font-family: Helvetica, Arial Unicode MS, Arial, sans-serif;
        font-size: small;
      }
      
      .my-css-class {
      
      }
      
  • Create client bundle file: com.myapp.client.Resources.java:
    • package com.myapp.client;
      
      import com.google.gwt.core.client.GWT;
      import com.google.gwt.resources.client.ClientBundle;
      import com.google.gwt.resources.client.CssResource;
      public interface Resources extends ClientBundle {
        
        public static final Resources INSTANCE = GWT.create(Resources.class);
      
        public interface Style extends CssResource {
          @ClassName("my-css-class")
          myCssClass();
        }
      
        @ClientBundle.Source("resource/myapp.css") // relative path to the css file.
        @CssResource.NotStrict // No compile error if no css class in the css file.
        Style css();
      }
      
  • In the entry point class: com.myapp.client.MyAPP.java
    • package com.myapp.client;
      
      public class MyApp implements EntryPoint {
      
        public void onModuleLoadSafe() {
      
          // Inject the css
          Resources.INSTANCE.css().ensureInjected();
      
          // ... ... ...
      
        }
      
      }
      



No comments:

Post a Comment