Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:28:14+00:00 2026-05-27T00:28:14+00:00

Simple example. I have 2 styles declared in UiBinder: <ui:style> .success { font-size: 13px;

  • 0

Simple example. I have 2 styles declared in UiBinder:

    <ui:style>
    .success {
        font-size: 13px;
        margin: 15px;
        font-weight: bold;
        display: inline;
        padding: 3px 7px;
        background: #FFF1A8;
    }
    .error {
        font-size: 13px;
        margin: 15px;
        font-weight: bold;
        display: inline;
        padding: 3px 7px;
        background: #990000;
        color: #fff;
    }
</ui:style>

I also have a label that one of them is applied too.

    <g:Label ui:field="statusLabel" styleName='{style.success}' />

Within UiBinder, is there a way that I would be able to go about programatically switching the style to the error style? It’s nice being able to organize my CSS right there in the widget, and I haven’t found another good way of organizing it.

If what I’m asking isn’t possible, how should I be organizing my CSS in gwt, so that I don’t end up with a giant pool of styles, and is also easy, and usable? I imagine there is a smart way to use a ClientBundle for this, but I haven’t figured it out. I also think it’d be more convenient to be able to do the above mentioned way by just keeping everything in UiBinder without messing with another file. Either way, please help me before this gets out of hand!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:28:14+00:00Added an answer on May 27, 2026 at 12:28 am

    Yes, you have to do it in you code behind file. A description can be found here:
    Programmatic access to inline Styles.

    Here is an example:

    testBinder.ui.xml

    <!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
    <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
        xmlns:g="urn:import:com.google.gwt.user.client.ui">
        <ui:style type='XXXXXXXXXXX.client.testBinder.MyStyle'>
            .enabled {
                color: black;
            }
    
            .disabled {
                color: gray;
            }
        </ui:style>
        <g:HTMLPanel>
            <g:Button ui:field="button" text="ChangeButton" styleName="{style.enabled}" />
    
        </g:HTMLPanel>
    </ui:UiBinder> 
    

    testBinder.java

    package XXXXXXXXXXX.client;
    
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.resources.client.CssResource;
    import com.google.gwt.uibinder.client.UiBinder;
    import com.google.gwt.user.client.ui.Composite;
    import com.google.gwt.user.client.ui.Widget;
    import com.google.gwt.uibinder.client.UiField;
    import com.google.gwt.user.client.ui.Button;
    import com.google.gwt.uibinder.client.UiHandler;
    import com.google.gwt.event.dom.client.ClickEvent;
    
    public class testBinder extends Composite {
    
        private static testBinderUiBinder uiBinder = GWT
                .create(testBinderUiBinder.class);
        @UiField
        Button button;
    
        @UiField
        MyStyle style;
    
        interface MyStyle extends CssResource {
            String enabled();
    
            String disabled();
        }
    
        interface testBinderUiBinder extends UiBinder<Widget, testBinder> {
        }
    
        public testBinder() {
            initWidget(uiBinder.createAndBindUi(this));
        }
    
        boolean enabled = true;
    
        @UiHandler("button")
        void onButtonClick(ClickEvent event) {
            if(enabled){
                enabled = false;
                button.setStyleName(style.disabled());
            }
            else{
                enabled = true;
                button.setStyleName(style.enabled());
            }
        }
    }
    

    If you click this button, you can see the it’s style changing according to your CSS definition in your UiBinder file. (In this case switching from black to gray an visa verse)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone have a simple example of implementing an async validation rule in csla?
I have seen simple example Ajax source codes in many online tutorials. What I
A simple example: Let's say I have one alias being sourced somewhere as: alias
I have this very simple example that I am using to learn structs in
I have this simple example I can't seems to get working : MERGE INTO
Below I have a very simple example of what I'm trying to do. I
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
Have a look a this simple example. I don't quite understand why o1 prints
I am currently learning F# and have tried (an extremely) simple example of FizzBuzz.
I've been looking all over for a simple example of how to have an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.