-->

Adding style to a ButtonCell

2019-08-08 22:57发布

问题:

I know my question is considered initially to refer to the "very novice" level, but I have spent quite o lot of time on searching for the answer. I have used in a gwt application a DataGrid and I have attached a diversity of specific Cell widgets (i.e. TextCell, ButtonCell). My concern is how I can add and handle styling to the button of a ButtonCell through custom css. The code which implements the column of ButtonCells looks like as follows:

Column<FilterInfo, String> delButtonColumn = new Column<FilterInfo, String>(new ButtonCell()) {

  @Override
  public String getValue(FilterInfo object) {
    return "X";
  }
};

So, how can I add styling to the button (not to the entire Cell)? I suspect that I should also override the render function, however I cannot figure out how the styling is applied

@Override
public void render(Context context, FilterInfo object, SafeHtmlBuilder sb) {
  super.render(context, object, sb);
      ???
}

回答1:

You can use the setCellStyleNames() method in Column to apply a style that will be applied to every cell of the column. You have to use GWT 2.4 for this to work. It will probably be something like that. Please note that the code was written outside of any IDE, so it may contain errors.

Column<FilterInfo, String> delButtonColumn = new Column<FilterInfo, String>(new     ButtonCell()) {

  @Override
  public String getValue(FilterInfo object) {
    return "X";
  }
};
delButtonColumn.setCelLStyleNames("yourStyleName");

And the css :

.yourStyleName.gwt-Button{
  //your styling here
}