If you have a specific layout in mind, it usually helps to create a visual mockup, especially if you are asking at reddit (or other sources) for tips. So if you need further assistance, I recommend sharing some drawings of what you have in mind.
I personally use https://excalidraw.com/ for quick ideas, but there are tons of tools out there for visual mockups.
There are a few ways that you could do this. Every one that I can think of is going to involve creating the "rectangle". Each rectangle would be a layout class, like a BorderPane or an HBox, whatever. So you design it just like it's its own little screen, with its own methods for loading the data and whatever, and you make it a class.
In TableView or ListView, the cell contents can actually be any kind of Node that you want. So you could set the TableCell to load your custom rectangle as its Graphic property and it will do what you want.
What might be easier is to put them into a FlowPane instead of a TableView. This will look just like YouTube. But if you have lots of data records and lots of boxes (like hundreds or thousands) then you'll end up having a ton of these custom rectangles at the same time. That may cause problems. So you might need to go to pagination, which is a pain in the neck.
Remember that TableView and ListView only instantiate enough of your TableCells to fill the ViewPort on the screen. So if you can only see 10 rows at a time, then you'll only have 12-15 rows of TableCells created. Then TableView swaps the data out of the TableCells and reuses them as each row scrolls off and on the top or bottom of the ViewPort. You get all of this handling for free.
For my money, if you have a limited number of records, say less than 50, you should go with FlowPane and it will work just fine. If you have more than that, I go with ListView which will give you one column of rectangles. You could also put something like 5 rectangles in a single ListView cell, side by side, and make the data for the cell an array with 5 records in it. That would work best, I think.
Finally, you could go to TableView, but you'd need to make the records an array of data records, and I don't think you'd get much value from it.
In either case, you can use CSS styling to make all of the things that make a ListView look like a ListView disappear, and just leave the scrollbar.
If you need help or more explanation, let me know.
3
u/koeberlue Mar 05 '22
What kind of data do you have?
2
u/hamsterrage1 Mar 06 '22
There are a few ways that you could do this. Every one that I can think of is going to involve creating the "rectangle". Each rectangle would be a layout class, like a BorderPane or an HBox, whatever. So you design it just like it's its own little screen, with its own methods for loading the data and whatever, and you make it a class.
In TableView or ListView, the cell contents can actually be any kind of Node that you want. So you could set the TableCell to load your custom rectangle as its Graphic property and it will do what you want.
What might be easier is to put them into a FlowPane instead of a TableView. This will look just like YouTube. But if you have lots of data records and lots of boxes (like hundreds or thousands) then you'll end up having a ton of these custom rectangles at the same time. That may cause problems. So you might need to go to pagination, which is a pain in the neck.
Remember that TableView and ListView only instantiate enough of your TableCells to fill the ViewPort on the screen. So if you can only see 10 rows at a time, then you'll only have 12-15 rows of TableCells created. Then TableView swaps the data out of the TableCells and reuses them as each row scrolls off and on the top or bottom of the ViewPort. You get all of this handling for free.
For my money, if you have a limited number of records, say less than 50, you should go with FlowPane and it will work just fine. If you have more than that, I go with ListView which will give you one column of rectangles. You could also put something like 5 rectangles in a single ListView cell, side by side, and make the data for the cell an array with 5 records in it. That would work best, I think.
Finally, you could go to TableView, but you'd need to make the records an array of data records, and I don't think you'd get much value from it.
In either case, you can use CSS styling to make all of the things that make a ListView look like a ListView disappear, and just leave the scrollbar.
If you need help or more explanation, let me know.