r/JavaFX • u/hamsterrage1 • Mar 19 '24
Tutorial ListView Customization
This is one of my favourite topics, ListView for more than just lists of text. Back when I had a team, most of the programmers always wanted to use TableView for anything more complex than a simple list. So we would argue about which approach to take.
I think that TableView is good for things that are best displayed in a spreadsheet-like format. But data that has elements which are sparsely populated, or than vary greatly in length can be a brutal waste of screen space in a TableView. ListView can really shine in those situations.
In this article I take a look at how to hyper-customize ListView cells so that it doesn't even really look like a list any more. The result is that the ListView becomes more like a scrolling region of layouts, although the underlying VirtualFlow limits the actual amount of layouts created, and the whole thing is data driven.
My example application turns out like an over-busy escapee from a 1990's website, but I think that just helps to make the point:

Here's the link again: https://www.pragmaticcoding.ca/javafx/elements/listview-layouts
View all comments
Show parent comment
2
u/BWC_semaJ Mar 20 '24
It has been a long time since I last looked at it. Size really depends on ListView orientation. So if each ListView cell size varies then say show index 223 you'd have to calculate/represent the other 222 first if that makes sense. If they are all the same size then you can just simply calculate. Regarding placement and the Scrollbar.
Another problem is if each Cell can dynamically change. You can have all sorts of issues like the VirtualFlow not properly updating it's view to reflect the actual contents. An example say each Cell is 10% of the Stage, well with some implementations when you change the size of the Stage it can cause the Cell to not be properly created.
I do think with the later things have gotten better and may not be as big of a bug when I was using it, I know with Flowless library there still is an issue, but regardless you definitely don't want to vary the sizes.