PDA

View Full Version : Grid Column width



tvseshagiri
14 Dec 2010, 8:13 AM
Hi,

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.

sven
14 Dec 2010, 8:17 AM
columnConfig.setWidth(mywidth);

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);