When tableview is created, the default behaviour of columns is to leave a lot of empty space. Is there a way to automatically fill the space?
One solution is described here: JavaFX 2 Automatic Column Width but this seems a little cumbersome.
When tableview is created, the default behaviour of columns is to leave a lot of empty space. Is there a way to automatically fill the space?
One solution is described here: JavaFX 2 Automatic Column Width but this seems a little cumbersome.
TornadoFX comes with an advanced column resize policy called SmartResize
. You assign it to a TableView like this:
columnResizePolicy = SmartResize.POLICY
By default it tries to do something useful depending on the data, and it will assign any left over width to the last column.
You can configure resizing options per column by calling the appropriate configurator function. For example, to tell the policy to give remaining width to a given column:
column("Name", Person::nameProperty).remainingWidth()
You can configure multiple columns to receive remaning width, so that they will share the remaining width between them.
contentWidth()
will make sure the column width fits the content, with optional additional padding: contentWidth(padding = 50.0)
.
Most resize options also take an optional useAsMin
parameter which will enforce the given setting as a minimum width for the column. useAsMax
does the same for max width. You will get a fixed size by setting both useAsMin
and useAsMax
or specifying the fixedWidth(width)
option.
You can distribute space using the weigthedWidth(weightNum)
function, or even the pctWidth(pctNum)
function. All these modes can be combined
Please see the TornadoFX Guide chapter about the resize policy for more information: