I am trying to retain my JavaFx Tableview sorting order after data in the table is reloaded. I am following the below mentioned link. Javafx: Re-sorting a column in a TableView
TableView rooms;
...
TableColumn sortcolumn = null;
SortType st = null;
if (rooms.getSortOrder().size()>0) {
sortcolumn = (TableColumn) rooms.getSortOrder().get(0);
st = sortcolumn.getSortType();
}
Then, after you are done updating the data in the TableView, you must restore the lost sort-column state and perform a sort.
if (sortcolumn!=null) {
rooms.getSortOrder().add(sortcolumn);
sortcolumn.setSortType(st);
sortcolumn.setSortable(true); // This performs a sort
}
Everything works fine...sorting order is retained but the console is showing an exception at "rooms.getSortOrder().add(sortcolumn);"
Exception in thread "JavaFX Application Thread" java.lang.IndexOutOfBoundsException
at com.sun.javafx.scene.control.ReadOnlyUnbackedObservableList.subList(ReadOnlyUnbackedObservableList.java:136)
at javafx.collections.ListChangeListener$Change.getAddedSubList(ListChangeListener.java:242)
at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.handleSelectedCellsListChangeEvent(TreeTableView.java:3244)
at javafx.scene.control.TreeTableView$TreeTableViewArrayListSelectionModel.access$2000(TreeTableView.java:2289)
at javafx.scene.control.TreeTableView.sort(TreeTableView.java:1817)
at javafx.scene.control.TreeTableView.doSort(TreeTableView.java:1855)
at javafx.scene.control.TreeTableView.lambda$new$114(TreeTableView.java:383)
at com.sun.javafx.collections.ListListenerHelper$Generic.fireValueChangedEvent(ListListenerHelper.java:329)
at com.sun.javafx.collections.ListListenerHelper.fireValueChangedEvent(ListListenerHelper.java:73)
at javafx.collections.ObservableListBase.fireChange(ObservableListBase.java:233)
at javafx.collections.ListChangeBuilder.commit(ListChangeBuilder.java:482)
at javafx.collections.ListChangeBuilder.endChange(ListChangeBuilder.java:541)
at javafx.collections.ObservableListBase.endChange(ObservableListBase.java:205)
at javafx.collections.ModifiableObservableListBase.add(ModifiableObservableListBase.java:155)
at java.util.AbstractList.add(AbstractList.java:108)
at com.honda.galc.client.qi.repairentry.RepairEntryController.loadInitialData(RepairEntryController.java:260)
at com.honda.galc.client.qi.repairentry.RepairEntryController.markDefectAsActualProblem(RepairEntryController.java:529)
at com.honda.galc.client.qi.repairentry.RepairEntryController.addRepairMethods(RepairEntryController.java:184)
Any idea why such exception is coming?