2

... where T is the generic type of the TableView.

I'm implementing a file-listview with three columns, so far. Each of type java.nio.file.Path. For the name column, I wrote a Comparator<Path> which sorts the files with directories-first and case-insensitiv. The other two comparators sort by last-modified-time and file-size. For this they compare on long fields.

But the comparatorProperty of a column is based on Comparator<String>. Which, I think, sorts based on the displayed text...

So I have to find a way, to use the sort-on-header-click feature with the type of the TableView?

Christian Rädel
  • 581
  • 1
  • 5
  • 13
  • 2
    Can you post some code? I don't really understand what the types of your `TableView` and `TableColumn`s are. `TableView`, `TableColumn`, `TableColumn`, `TableColumn` would be the obvious choices but these don't seem to match your description. – James_D Aug 19 '15 at 02:10
  • looks like you simply mis-read the api doc ... can't see a comparator , it's [comparator](https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TableColumnBase.html#comparatorProperty) with T being the type of the column data :-) – kleopatra Aug 19 '15 at 08:05
  • You're both right. I misunderstood the description of ```T``` parameter in ```TableColumnBase```. So I had ```TableColumn```, instead of ```TableColumn```, for example. After I had changed this, I could use ```Comparator```. Thank you. :) – Christian Rädel Aug 19 '15 at 10:23
  • you might consider answering and accepting your own question - the solution is easier to find for future readers :-) – kleopatra Aug 28 '15 at 08:40

1 Answers1

2

You use wrong type parameters, when creating your TableColumn. If you create a TableColumn<Path, Path>, you can specify a Comparator<Path> for that column. Likewise TableColumn<Path, FileTime> and TableColumn<Path, Long> to use Comparator<FileTime> and Comparator<Long>.

From the docs:

Class TableColumnBase<S,T>
Type Parameters:
S - The type of the UI control (e.g. the type of the 'row').
T - The type of the content in all cells in this table column.
Christian Rädel
  • 581
  • 1
  • 5
  • 13