0

I use TableView for a small table of few entries that should consume only as much screen space as needed to display them.

TableView by default creates lots of blank rows that have no backend model data and consumes space. I've performed a search there and discovered only a way to color all blank rows with solid white and let them still steal screen space from other widgets.

So, is it possible at all to get rid of empty rows?

ayvango
  • 5,867
  • 3
  • 34
  • 73
  • possible duplicate of [JavaFX - Adapt TableView height to number of rows](http://stackoverflow.com/questions/27945817/javafx-adapt-tableview-height-to-number-of-rows) – eckig Jan 30 '15 at 09:39
  • @eckig You are right, this answer is a duplicate. But solution proposed in the existed question is a hack not applicable to general cases. – ayvango Jan 30 '15 at 11:38
  • Why is it a hack? The solution used public API only, no special Skin or CSS magic done.. – eckig Jan 30 '15 at 11:43
  • It sets row height to predefined constant. It supposes that size for caption is related to row size as 1:1.01. It does not prevent TableView from creating orphan TableCells, it just recalculate table height and force TableView delete rows after resizing, but rows are still created. – ayvango Jan 30 '15 at 12:33
  • some more ideas: http://stackoverflow.com/q/26298337/203657 – kleopatra Jan 30 '15 at 13:01
  • 1
    @eckig - I agree with OP here, magic numbers are evil, always ;-) – kleopatra Jan 30 '15 at 13:29
  • @ayvango It is not a predefined constant. The fixed cell size is just a number, you can set it to 10, 300, 50000 whatever you like. It just there to show you how it is done and it can only work if you can assert that all rows have the same height. The rest of my example is done via Bindings.. – eckig Jan 30 '15 at 13:52
  • @eckig your created a TableCell implementation, managed somehow to calculate its height. And after that you have applied new css to the table and see how it gets disturbed by a code constant that does not match to css. As for the second link, I find it more promising – ayvango Jan 30 '15 at 14:02
  • @ayvango are we talking about the same thing here? My answer does not use a custom cell nor does it use custom CSS. Plain Java code, no internal API and no constant values. Just a single number that can freely be adjusted. Im out.. – eckig Jan 30 '15 at 14:18
  • @eckig others may found complicated table views with custom cells and css usefull. And they still face the same problem with blank lines. So you need a solution that can address this cases too. – ayvango Jan 30 '15 at 14:38

0 Answers0