0

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.

Community
  • 1
  • 1
atok
  • 5,880
  • 3
  • 33
  • 62

1 Answers1

3

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:

Edvin Syse
  • 7,267
  • 18
  • 24
  • Thats more then I expected :D Thank you! – atok Feb 10 '17 at 15:12
  • You're welcome :) It probably hasn't seen wide spread usage yet, so please let me know if you run into any issues. – Edvin Syse Feb 11 '17 at 14:53
  • How do you use it from Java/Sacla? – woky Dec 12 '17 at 18:23
  • TornadoFX is made for use with Kotlin only, although some functions can be called from other JVM languages as well. It's possible to call these functions, but it would be cumbersome and look weird. – Edvin Syse Dec 12 '17 at 20:08