DoubleClickListener on HeaderRowCells in Grid in vaadin 8.5.2

How is it possible to add a DoubleClickListener to the Header Row Cells of Grid, (target is to resize to maximum width oder snap to minimum width) if clicked? I couldn’t find an appropriate code snippet.
Every recommendation is highly appreciated.

Since Grid header cells allow using components in them, maybe you could place e.g. a Button or a Layout in the header cell and have that handle the click events.

-Olli

Thank you for you fast answer, dear Olli.
Unfortunately I was not clear,sorry: I mean the mainHeaderRow, which allows neither adding Components nor adding Listeners.
I would like to avoid to create an additional headerRow for this purpose.
Do you have an alternative recommendation?

HeaderRow doesn’t allow adding components, but HeaderCell does. Something like this: grid.getHeaderRows().get(0).getCell(someColumn).setComponent(someComponent);

-Olli

Dear Olli
I managed to implement what you wrote. I noticed that it is possible to add Components to the MainHeader-Cells, I was confused by “setComponent” instead of “addComponent”, sorry.
Unfortunately, the added Text vanishes in the Cell so I gave up the idea to have small visible buttons at the left hand of the cell.
I added transparent Buttons (with a little overriding in Valo Theme borderless) with the column caption as Caption; so the sorting function is reached by clicking at the right side of the header cell, expanding/shrinking by click on the caption. Not really what I wanted (DoubleClick …) but OK for me.
Thank you very much.
Elke