I am working on javaFx application and have created a tableview and have around 100,000+ rows with 10 columns.
I have also created same table using java swing Jtable.
Now I need sorting performance to be better in javaFx if not better than some what near to java swing's jtable.
Right Now I am using sortorder() which sort data by clicking on column headers and sort speed is 20 times slower than Jtable.
Can anyone please help ?
Thank You
Edit:
I am using example 13.8 in this link http://docs.oracle.com/javafx/2/ui_controls/table-view.htm just has added few line of code to just add 100,000 rows by generating random data.
I don't know what's up with the speed of the sort on the TableView when you click on the table header - it gets slow with 100,000 rows as you mention in your question.
If you just provide a button which sorts the underlying collection, it sorts many times quicker and the table updates fine (at least under Java 8). Time to sort a column was well under a second.
Or using Java 8 lambdas:
So if you have a lot of items in your table, on the column call setSortable(false) and provide buttons for the user to sort table columns if you need to.
Plugging my laptop into the wall and increasing the maximum memory of the JVM also increased sort performance for large data sets (cutting the time to sort by clicking on a column header with the sample below from 20 seconds to about 10 seconds).
File an enhancement request against the JavaFX issue tracker with the following sample code. The code generates 100,000 rows of random data, and you can check the performance of standard column sorting by clicking on a table column header to sort on a table column and compare that with the performance of sorting by
Collections.sort
invoked by pressing buttons.It took a while, but I think I have figured this out, at least for this example.
In this example, the Person class doesn't have any property accessors (i.e. there's a getFirstName() method, but no firstNameProperty() method). Sorting by columns has to access the value in each cell in the column via the cell value factory. When there's no property accessor, the cell value factory is going to call getFirstName() and then wrap the result in a new ReadOnlyObjectWrapper on each invocation.
If you make sure the class representing the row data has the appropriate property accessors, then retrieving the value is much more efficient, as it merely returns a reference to the existing StringProperty.
This example sorts 100,000 rows in approximately a second on my system (MacBookPro 8GB RAM, quad core). You can improve performance more by providing an explicit cell value factory, which gets around the need for reflection in computing the cell value. In other words, replace
with
The performance saving here is not as dramatic.
Here's the full example:
UPDATE: Note this is fixed in JavaFX 8.