Views
7 months ago

tornadofx-guide

Advanced Data Controls

Advanced Data Controls Figure 13.4 An alternative approach to percentage width is to specify a weight. This time we add weights to both Number and Type: column("Number", Room::number).weigthedWidth(1.0) column("Type", Room::type).weigthedWidth(3.0) The two weighted columns share the remaining space after the other columns have received their fair share. Since the Type column has a weight that is three times bigger than the Number column, its size will be three times bigger as well. This will be reevaluated as the TableView itself is resized. Figure 13.5 198

Advanced Data Controls This setting will make sure we keep the mentioned ratio between the two columns, but it might become problematic if the TableView is resized to be very small. The the Number column would not have space to show all of its content, so we guard against that by specifying that it should never grow below the space it needs to show its content, plus some padding, for good measure: column("Number", Room::number).weigthedWidth(1.0, minContentWidth = true, padding = 10 .0) This makes sure our table behaves nicely also under constrained width conditions. Dynamic content resizing Since some of the resizing modes are based on the actual content of the columns, they might need to be reevaluated even when the table or it's columns aren't resized. For example, if you add or remove content items from the backing list, the required content measurements might need to be updated. For this you can call the requestResize function after you have manipulated the items: SmartResize.POLICY.requestResize(tableView) In fact, you can ask the TableView to ask the policy for you: tableView.requestResize() Statically setting the content width In most cases you probably want to configure your column widths based on either the total available space or the content of the columns. In some cases you might want to configure a specific width, that that can be done with the prefWidth function: column("Bed", Room::bed).prefWidth(200.0) A column with a preferred width can be resized, so to make it non-resizable, use the fixedWidth function instead: column("Bed", Room::bed).fixedWidth(200.0) 199

GUIDE
GUIDE
GUIDE
GUIDE
Guide
GUIDE
Guide
Guide
Guide
GUIDE
GUIDE
GUIDE
GUIDE
Guide
GUIDE
GUIDE