开发者

How can I right-align a cell in a Wicket table column?

开发者 https://www.devze.com 2023-04-12 02:33 出处:网络
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 t

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"));
}
0

精彩评论

暂无评论...
验证码 换一张
取 消