I'm using a treeview in a javafx application and today I added drag and drop support to reorder the elements of the treeview. To do this i had to create my own CellFactory class but my code has a bug. When the content of my treeview gets smaller the area under the treeview that should be empty still contains text that shouldn't be there.
This is what my treeview looks like before collapsing and after collapsing:
I got my inspiration for the drag and drop feature from this blogpost https://brianyoung.blog/2018/08/23/javafx-treeview-drag-drop/
Before I had my own cellFactory class I had a lambda function in the setCellFactory method of my treeview and that solution didn't have this problem.
In my CellFactory class I override the call method. I think this is where i need to somehow refresh the content of the treeview to get rid of the residue text.
public class CellFactory implements Callback<TreeView<QuizElement>, TreeCell<QuizElement>> {
...
@Override
public TreeCell<QuizElement> call(TreeView<QuizElement> treeView) {
TreeCell<QuizElement> cell = new TreeCell<QuizElement>() {
@Override
protected void updateItem(QuizElement item, boolean empty) {
super.updateItem(item, empty);
if (item == null) return;
if (empty) {
setText("");
} else {
textProperty().bind(item.getNameProperty());
}
}
};
cell.setOnDragDetected((MouseEvent event) -> dragDetected(event, cell));
cell.setOnDragOver((DragEvent event) -> dragOver(event, cell));
cell.setOnDragDropped((DragEvent event) -> drop(event, cell, treeView));
cell.setOnDragDone((DragEvent event) -> clearDropLocation());
return cell;
}
...
In the after collapsing picture I expected the area under the last openable element to be white.