Reputation: 86925
I have a GWT TextButton
. The following css styles applied to the global css file do nothing:
.gwt-TextButton {
color: red !important;
}
Why? What are the correct styles to be applied to change the style of all TextButton widgets?
Upvotes: 2
Views: 468
Reputation: 3048
TextButton
is a cell-backed widget and is based on the appearance pattern. It uses a TextButtonCell
to render the content and wraps it using CellWidget<T>
.
The global css you are looking for is gwt-ButtonCellBase
but it is obfuscated because is used in a ClientBundle
, so you need to extend ButtonCellBase.DefaultAppearance.Resources
, providing your own Style
. Much like any other cell-based widget. Then you need to use the right constructor (TextButton(Appearance appearance, String text)
). Sample code follows.
Define the resource appearance extension (fully quoted for clarity):
public interface MyResources extends ButtonCellBase.DefaultAppearance.Resources {
@Override
@Source(value = {ButtonCellBase.DefaultAppearance.Style.DEFAULT_CSS, "custom.css"})
ButtonCellBase.DefaultAppearance.Style buttonCellBaseStyle();
}
Inside custom.css
, override whatever you want of ButtonCellBase.css
, and then inject everything:
MyResources customResources = GWT.create(MyResources.class);
TextButtonCell.Appearance customAppearance = new TextButtonCell.DefaultAppearance(customResources);
TextButton button = new TextButton(customAppearance, "Text");
You can very well do all the above just once, and always instantiate any new TextButton
with the same appearance.
Upvotes: 2