I have been trying to figure out how to auto-size TreeView columns to fit their content for a while now. This has been asked before, but the response was minimal and not acceptable.
[javafx column in tableview auto fit size
Curiously, the behavior I'm looking for is exactly what happens when you double-click a column resize line in TableView. However, I have been unable to figure out how this occurs when looking through the JavaFX source code.
Does anyone know how/where the double-click behavior on a column resize line is handled in JavaFX TableView/TableColumn/TableColumnHeader?
If possible, I would simply like the columns to automatically do at first render what happens when you double-click the resize line. How this isn't already one of the available pre-created column size constraint policies is beyond me.
Best Answer
The solution that works for me on JavaFX8:
Set the
columnResizePolciy
toCONSTRAINED_RESIZE_POLICY