TableView column resizer extension function
See original GitHub issueOne thing that frustrated me for awhile is having a way to fit TableView
columns to the header and cell contents. Then I found a little gem in a Stack Overflow post.
I was able to come up with this class to expose that resizeColumnToFitContent()
public final class TableColumnResizer<T> extends TableViewSkin<T> {
public TableColumnResizer(TableView<T> tableView) {
super(tableView);
}
@Override
public void resizeColumnToFitContent(TableColumn<T, ?> tc, int maxRows) {
super.resizeColumnToFitContent(tc,maxRows);
}
}
Then I can apply that TableViewSkin
to the skinProperty()
, and call a resizeOp
function at any time to re-fit the columns.
var resizeOp: (() -> Unit) by singleAssign()
//layout built here
tableView.apply {
val resizerSkin = TableColumnResizer<FTRecord>(this);
skinProperty().set(resizerSkin)
resizeOp = { columns.forEach { resizerSkin.resizeColumnToFitContent(it, 100) } }
}
It would be awesome if we could apply a resizeColumns()
extension function to the TableView
. The problem is I can’t think of an efficient way at the top of my head without extending TableView
or doing some lazy operation that stores state elsewhere. It’s really too bad extension properties can’t be fields.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
JavaFX TableColumn resize to fit cell content - Stack Overflow
Save this question. Show activity on this post. I'm looking for a way to resize a TableColumn in a TableView so that all...
Read more >TableView (JavaFX 8) - Oracle Help Center
Applies the currently installed resize policy against the given column, resizing it based on the delta value provided. ObjectProperty<Callback<TableView<S>, ...
Read more >setAutoresizesAllColumnsToFit - Apple Developer
If flag is YES , the difference in width is distributed among the table view's table columns; if flag is NO , only...
Read more >Resize Tables and Cells - Tableau Help
You can change the size of the rows, columns, and cells that compose a table. The best way to resize your table depends...
Read more >TableView.AllowBestFit Property | WPF Controls
BestFitColumn method. To resize all columns, use the TableView.BestFitColumns method. End-users can resize columns to their optimal width (if allowed) by ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Brilliant! Works perfectly. Thanks Edvin, that was pretty clever.
Okay awesome, ill play with it again when I get back to my tablet.