This is what CSS is used for.
Label label = new Label("your text");
label.setStyleName("myStyle");
And in your .css file:
.myStyle {
background-color: #f00;
}
Or if you use UIBinder:
<ui:style>
.myStyle {
background-color: #f00;
}
</ui:style>
<g:HTMLPanel>
<g:Label styleName="{style.myStyle}">Your text</g:Label>
</g:HTMLPanel>
The advantage of the UIBinder approach is that your style is in the same file as Label, and the CSS name will also be confused.
source
share