Question

my code:

    List<ColumnConfig<Reminder, ?>> ccs = new LinkedList<ColumnConfig<Reminder, ?>>();
    CheckBoxCell cbc = new CheckBoxCell();
    ColumnConfig<Reminder,Boolean> applicableColumn = new ColumnConfig<Reminder,Boolean>(properties.applicable(),100,"Applicable");
    applicableColumn.setCell(cbc);
    applicableColumn.setAlignment(HasHorizontalAlignment.ALIGN_CENTER);

This does not work.

Was it helpful?

Solution

I realize that this answer is probably too late for your purposes, but it may help someone looking for the same question. Here's the code that I use:

private void centerCheckBox(final ColumnConfig<Pet, ?> columnConfig) {
  final int leftPadding = (columnConfig.getWidth() - 12) / 2;
  final String styles = "padding: 3px 0px 0px " + leftPadding + "px;";
  final SafeStyles textStyles = SafeStylesUtils.fromTrustedString(styles);
  columnConfig.setColumnTextStyle(textStyles);
}

In addition to calling this method for each checkbox after the ColumnConfig is created I also call it for each checkbox column in the ColumnWidthChange event handler (the event handler is added to the ColumnModel). Here's my code for the column width change handler (note: I add each checkbox column config to a set when I create the ColumnConfig instances):

columnModel.addColumnWidthChangeHandler(new ColumnWidthChangeHandler() {
  @Override
  public void onColumnWidthChange(final ColumnWidthChangeEvent event) {
    final ColumnConfig<Pet, ?> petColumnConfig = columnConfigList.get(event.getIndex());
    if (_checkBoxSet.contains(petColumnConfig)) {
      centerCheckBox(petColumnConfig);
      _grid.getView().refresh(true);
    }
  }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top