So i have figured out how to get all the files and directories and add them to the treeview but it shows me the complete file path: C/user/file.txt i just want the file or f
Use a custom cellFactory
to determine, how the items are shown in the TreeView
:
treeView.setCellFactory(new Callback<TreeView<File>, TreeCell<File>>() {
public TreeCell<File> call(TreeView<File> tv) {
return new TreeCell<File>() {
@Override
protected void updateItem(File item, boolean empty) {
super.updateItem(item, empty);
setText((empty || item == null) ? "" : item.getName());
}
};
}
});