I have a TableView that shows program names (String) and times (LocalDateTime). When I open it, it is automatically sorted by time. But when I click to the new button, add a new item to the row, the new item is the first item in the table. After clicking on the column name of time, it still doesn't put it in its place (it's either the first or last item).
I'm trying to write here all the codes relating to it.
programTable = new TableView<>();
programTable.setEditable(true);
ObservableList<Program> programs = weddingScriptController.getPrograms();
SortedList<Program> sortedData = new SortedList<>(programs);
sortedData.comparatorProperty().bind(programTable.comparatorProperty());
Button newButton = new Button("Új");
newButton.setOnAction(e -> {
ProgramCreateWindow window = new ProgramCreateWindow();
window.display(programs);
});
//other stuff
TableColumn<Program, String> nameCol = new TableColumn<>("Név");
nameCol.setCellValueFactory(new PropertyValueFactory<Program, String>("name"));
TableColumn<Program, LocalDateTime> defaultTimeCol = new TableColumn<>("Idő");
defaultTimeCol.setCellValueFactory(new PropertyValueFactory<Program, LocalDateTime>("defaultTime"));
defaultTimeCol.setCellFactory(TextFieldTableCell.forTableColumn(new ProgramDateTimeStringConverter()));
defaultTimeCol.setSortType(TableColumn.SortType.ASCENDING);
//other stuff
programTable.setItems(sortedData);
programTable.getSortOrder().add(defaultTimeCol);
programTable.sort();
I've tried deleting that sorted list, and using the programs list, but it doesn't solve the problem.
programTable.setItems(programs);
I've also tried giving that function the sortedList, but it gets error when trying to add the new item to it.
window.display(sortedList);
What should I use to make this new item sorting work? I know that it may be a dumb question, but I don't get it how it works, what am I doing right, what am I doing wrong.