View Full Version : Grid Column width

14 Dec 2010, 8:13 AM

How to set Grid Column width dynamically depending on the column header text. As we need to support i18n column width is changing locale to locale. Is there any way to set it dynamically.

14 Dec 2010, 8:17 AM

This would set the column width.

You can use TextMetrics to calculate the size of the text. There are two steps required for this

1) Render the grid with just some width set on the column
2) After the grid fully rendered (including the header), you can use TextMetrics to get the width of the heading. For this you need to bind TextMetrics to the header element, get the width and than call
grid.getColumnModel().setColumnWidth(index, mywidth);