How can I right-align a cell in a Wicket table column?
I'd like to have a PropertyColumn
of a DataTable
right-aligne开发者_开发百科d. But if I try to add a new SimpleAttributeModifier("align", "right")
to the cell item, it is added to a span
within the td
, rather than the td
itself.
public class AssetSizeColumn<T> extends PropertyColumn<T> {
...
@SuppressWarnings("unchecked")
public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> rowModel) {
IModel<Long> model = (IModel<Long>) createLabelModel(rowModel);
Component label = new Label(componentId, model.getValue().toString());
label.add(new SimpleAttributeModifier("align", "right"));
item.add(label);
}
Can I get at the td
to set the alignment?
The trick is that the td
is the parent of the item as soon as it is added to the ICellPopulator
, so that we can add a modifier to it straight away.
public void populateItem(Item<ICellPopulator<T>> item, String componentId, IModel<T> rowModel) {
IModel<Long> model = (IModel<Long>) createLabelModel(rowModel);
Component label = new Label(componentId, model.getObject().toString());
item.add(label);
label.getParent().add(new SimpleAttributeModifier("align", "right"));
}
精彩评论