I'm developing a small game that has a highscore list displayed by a javafx TableView
. I've created a subclass HighscoreTableView extends TableView
which is a TableView
node that automatically creates the TableColumns
I need and fills them with data on construction.
I want that table to be sorted by a default column on initialisation. I've added the following code lines:
duration.setSortType(TableColumn.SortType.DESCENDING);
this.getSortOrder().add(duration);
duration.setSortable(true);
this.sort();
where duration is the TableColumn
that should define the sorting. Of course, it's added to the TableView
. But when I create a new instance of that HighscoreTableView
, it remains unsorted by default, until the user clicks on one of the column headers. This is unexpected, since this question, this question and this question say it should work that way. Any ideas?
Further information for reproduction:
The HighscoreTableView
class is used by a HighscoreStage extends Stage
class, which contains a TabPane
with four Tabs. Each Tab contains a HighscoreTableView
with different data taken from a static Data
object. The data model is a class HighscoreEntry
, an ObservableList
of them gets added to the HighscoreTableView
s. My full code is available here.