Monday, May 31, 2010

Re: Need a way to get width of each column in a Grid

Never mind guys. Figured it out. Just in case there are any searches:

public CellFormatter cellFormatter = new CellFormatter();
public Element cellElement;

and then I made 2 methods that I found very useful within my class
that extends Grid:

public int getColumnWidth(int column) {
cellElement = cellFormatter.getElement(0, column);
return cellElement.getClientWidth();

public int getColumnOffset(int column) {
cellElement = cellFormatter.getElement(0, column);
return cellElement.getOffsetLeft();

in the getElement function you can specify a row also, but I chose to
use 0 because all my columns in a given row have the same width. Be
wary though, I've noticed it rounds. I used a similar method to get
the total width for the table, and then I subtracted all the column
widths while the borders were set to 0, and the result I got was -3.
So there is slight rounding going on, which is why I found the
getOffsetLeft method of Element so useful since its more accurate for
me to get exactly where something is placed.

Best of luck!

On May 31, 10:33 pm, spierce7 <> wrote:
> I'm trying to find a way to get the specific width of each column
> individually within a grid. Height isn't as important, but I wouldn't
> mind knowing that either. I don't need the table total width, but
> rather specific columns.
> Getting the absolute location of a cell, column, or row might also
> work. I've been looking for over an hour now and can't seem to find a
> way.

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment