0

I am trying to align a column in my cell table to the right. Therefore I use the "setHorizontalAlignment" of my column object. The resulting cell is actually rendered with the "align=right", but it is not aligned to the right because the cell contains another div that fills the complete cell.

Is this a bug in GWT or am I doing it wrong?

TextColumn<String> myColumn = new TextColumn<String>() {
    @Override
    public String getValue(String myObj) {
        return myObj;
    }
};
myColumn.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
myCellTable.addColumn(myColumn, "anyColumnName");

enter image description here

I know I can also align it right via CSS, but I hope, I can get this approach working because it seems to be the cleaner solution.

jan
  • 3,923
  • 9
  • 38
  • 78

2 Answers2

0

You can do it using css and Column#setCellStyleNames().

Sample code:

myColumn.setCellStyleNames("rightAlign");

css:

.rightAlign{
    text-align: right;
}

Note: change css as per your requirement

Braj
  • 46,415
  • 5
  • 60
  • 76
  • For another sample code have a look at [Dynamic styles for GWT cellTable cells](http://stackoverflow.com/questions/13361648/dynamic-styles-for-gwt-celltable-cells) – Braj May 01 '14 at 13:13
  • There is no need to do that if the alignment is set on the column. – Andrei Volgin May 01 '14 at 15:27
  • @AndreiVolgin yes you are right but if OP want to change it just for one column and a global css for all others columns to be left. – Braj May 01 '14 at 15:38
0

I have the same code, and it renders the same way - with a div element that takes 100% of the width. And the text inside this cell is displayed aligned to the right - as it should. So this is not a GWT bug.

There is another style in your CSS that interferes here. Most likely, you have something like this in your CSS:

td {
    text-align: left;
}
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58