I am programming a simple Questionare application. I use a TableView inside a custom javaFX component (representing one question) that is used as a ListCell inside a ListView (used to represent the entire questionnaire).
What I want: each ListCell uses as little space as possible (or necessary), while still ignoring its full content.
What happens: TableView has a default size by default. If the table has more content, it displays its contents in a ScrollPane. If the TableView has less content, it is filled with empty space.
I tried to solve my problem in several ways:
I initially suggested that there should be a way to deactivate scrollbars. But I could not find a way to do this.
Then I tried to resize the table by changing PreferredSizeProperty: table.setPrefHeight()
But I can not find any information about how big the table is. table.setPrefHeight(USE_COMPUTED_SIZE);
there was no result that I was hoping for.
Then I tried to calculate the necessary height myself, but could not find a way to determine the height of individual rows. Calling this.getTableRow().getHeight()
in the update method of a custom TableCell will result in NullPointerExceptions. If the checkbox is set to null, it will still return 0! TableRow<T> tr = this.getTableRow(); if (tr != null) { System.out.println(tr.getHeight()); }
Pretty upset, I decided to fix the row height by calling table.setFixedCellSize(20);
This greatly limits the point of custom TableCells, but I did not do anything else. However, the height of the table is also not equal to the number of rows times the fixed row height, since the table title must be taken into account. And I could not access the table header or set the size / height of the table headers.
Do you have any suggestions in which I did wrong, or what I missed to achieve my original goal? (Having a ListCell that is as large as necessary to display each row of the table, but not one empty row?) Any help / ideas would be greatly appreciated! Thanks!
source share