Rowsorting of TableView with SortedList/FilteredList

Jonathan Giles jonathan.giles at
Thu Aug 8 13:30:33 PDT 2013

Funny you should ask about this - I just blogged about SortedList and 
TableView the other day, over at FXExperience:

Of course, I can see that you've already read that post (I see a comment 
from the code in my post in your code below). What might have been 
missed is that I noted earlier on in the blog post I had to make a few 
small changes to properly get SortedList support in TableView, so you'll 
want to try again in b102 (or b103).

Regarding your use of FilteredList as well - I've not tried this at all, 
but I'll add it to my todo list to investigate today. I imagine there 
might be a bug somewhere. Whatever I find will probably make for a good 
post at FXExperience, so keep an eye out there too.

Thanks, and if you do run into further issues, please don't hesitate to 
file bugs. In general, if TableView isn't sorting then something is 
going really wrong!

-- Jonathan

On 8/08/2013 11:17 p.m., Martin Klähn wrote:
> Hi guys,
> I'm working on a business application that makes use of TableView and I'm
> working with JDK 8 build b101.
> Displaying the data works like a charm. Row sorting for ordinary
> ObservableLists is fine too.
> Then I've set TableView.items to FilteredList and row sorting was disabled.
> replacing TableView.item with SortedList does not allow row sorting as
> well. Binding the comparator of SortedList to the TableView.comparator has
> no effect either.
> // row sorting possible
> //final TableView<Integer> tableView = new
> TableView<>(FXCollections.observableArrayList(2, 1, 3));
> // row sorting not possible (SortedList)
> // create a TableView with the sorted list set as the items it will show
> // bind the sortedList comparator to the TableView comparator
> //SortedList<Integer> sortedList = new
> SortedList<>(FXCollections.observableArrayList(2, 1, 3));
> //sortedList.comparatorProperty().bind(tableView.comparatorProperty());
> //final TableView<Integer> tableView = new TableView<>(sortedList);
> // row sorting not possible (FilteredList)
> //FilteredList<Integer> filteredList = new
> FilteredList<>(FXCollections.observableArrayList(2, 1, 3), (e) -> true);
> //final TableView<Integer> tableView = new TableView<>(filteredList );
> // Don't forget to define columns!
> final TableColumn<Integer, Number> integerColumn = new
> TableColumn<>("Integer");
> final TableColumn<Integer, String> hexColumn = new TableColumn<>("Integer
> Hex");
> integerColumn.setCellValueFactory(javaClass -> new
> SimpleLongProperty(javaClass.getValue()));
> hexColumn.setCellValueFactory(javaClass -> new
> SimpleStringProperty(Integer.toHexString(javaClass.getValue())));
> tableView.getColumns().addAll(integerColumn, hexColumn);
> Any pointers on what I'm doing wrong or where I have to adapt my
> expectations.
> Is it correct that row sorting in a TableView is only possible for ordinary
> ObservableLists?
> With Regards
> Martin

More information about the openjfx-dev mailing list